{"id":176,"date":"2017-03-20T05:58:13","date_gmt":"2017-03-20T05:58:13","guid":{"rendered":"http:\/\/codeinsightacademy.com\/blog\/?p=176"},"modified":"2017-05-11T15:27:16","modified_gmt":"2017-05-11T15:27:16","slug":"beanfactory-and-application-context","status":"publish","type":"post","link":"https:\/\/codeinsightacademy.com\/blog\/java\/beanfactory-and-application-context\/","title":{"rendered":"BeanFactory and Application Context"},"content":{"rendered":"<p><strong>Bean Factory<\/strong><\/p>\n<ul>\n<li>Bean instantiation\/wiring<\/li>\n<\/ul>\n<p><strong>Application Context<\/strong><\/p>\n<ul>\n<li>Bean instantiation\/wiring<\/li>\n<li>Automatic BeanPostProcessor registration<\/li>\n<li>Automatic BeanFactoryPostProcessor registration<\/li>\n<li>Convenient MessageSource access (for i18n)<\/li>\n<li>ApplicationEvent publication<\/li>\n<\/ul>\n<hr \/>\n<p><strong>Bean Factory<\/strong><\/p>\n<p>&nbsp;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">BeanFactory beanFactory = new DefaultListableBeanFactory();\r\nXmlBeanDefinitionReader reader = new XmlBeanDefinitionReader((BeanDefinitionRegistry) beanFactory);\r\nreader.loadBeanDefinitions(new ClassPathResource(\"spring.xml\"));\r\n\r\nComponentClass cc = (ComponentClass) beanFactory.getBean(\"compclass\");\r\n<\/pre>\n<p>&nbsp;<\/p>\n<hr \/>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;bean id=\"compclass\" class=\"com.classes.ComponentClass\" \/&gt;<\/pre>\n<p>&nbsp;<\/p>\n<hr \/>\n<p><strong>Application Context<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">ApplicationContext context = new ClassPathXmlApplicationContext(\"spring.xml\");\r\nComponentClass cc = (ComponentClass) context.getBean(\"compclass\");<\/pre>\n<p>&nbsp;<\/p>\n<hr \/>\n<p>&nbsp;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;bean id=\"propertyConfigurer\" class=\"org.springframework.beans.factory.config.PropertyPlaceholderConfigurer\"\r\n      p:location=\"myproperties.properties\" \/&gt;\r\n\r\n&lt;bean id=\"compclass\" class=\"com.classes.ComponentClass\" p:age=\"${myp.age}\" \/&gt;<\/pre>\n<p>&nbsp;<\/p>\n<hr \/>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;bean id=\"compclass\" class=\"com.classes.ComponentClass\"&gt;\r\n    &lt;property name=\"age\" value=\"30\"\/&gt;\r\n&lt;\/bean&gt;<\/pre>\n<p>&nbsp;<\/p>\n<hr \/>\n<p>Ref:<\/p>\n<ol>\n<li>http:\/\/stackoverflow.com\/questions\/243385\/beanfactory-vs-applicationcontext<\/li>\n<li>http:\/\/stackoverflow.com\/questions\/5231371\/springs-xmlbeanfactory-is-deprecated<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Bean Factory Bean instantiation\/wiring Application Context Bean instantiation\/wiring Automatic BeanPostProcessor registration Automatic BeanFactoryPostProcessor registration Convenient MessageSource access (for i18n) ApplicationEvent publication Bean Factory &nbsp; BeanFactory beanFactory = new DefaultListableBeanFactory(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader((BeanDefinitionRegistry) beanFactory); reader.loadBeanDefinitions(new ClassPathResource(&#8220;spring.xml&#8221;)); ComponentClass cc = (ComponentClass) beanFactory.getBean(&#8220;compclass&#8221;); &nbsp; &lt;bean id=&#8221;compclass&#8221; class=&#8221;com.classes.ComponentClass&#8221; \/&gt; &nbsp; Application Context ApplicationContext context = new ClassPathXmlApplicationContext(&#8220;spring.xml&#8221;); [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts\/176"}],"collection":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/comments?post=176"}],"version-history":[{"count":3,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts\/176\/revisions"}],"predecessor-version":[{"id":249,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts\/176\/revisions\/249"}],"wp:attachment":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/media?parent=176"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/categories?post=176"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/tags?post=176"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}