I cannot figure the exact cause, but today my browsers started displaying web pages oddly - many Firefox pages were in bold font and many Chrome pages in italic font.
Turns out I'd somehow lost the Arial system font. On Windows 7 take a look at Control Panel -> Appearance and Personalization -> Fonts. In the Arial directory I had Arial Black, Bold, Italic, Narrow, etc... but no Arial Regular. I assume Firefox and Chrome were substituting the bold and italic fonts for the missing regular font.
Not certain this is the ideal solution, but it worked for me. Run this update:
http://www.microsoft.com/en-gb/download/details.aspx?id=16083
Arial Regular was now back in Fonts directory and all was well after restarting the browsers.
Wednesday 29 January 2014
Wednesday 22 January 2014
Spring ApplicationContext Bean Initialisation
Important Spring knowledge, but often poorly understood. Beans are created and initialised by the ApplicationContext as follows (following sequence done for each bean):
Let's write some code to illustrate this:
TestBean.java
TestBeanPostProcessor.java
application-context.xml (snippet)
output:
constructor
setter
TestBeanPostProcessor postProcessBeforeInitialization
postConstructInitialisation
afterPropertiesSet
init
TestBeanPostProcessor postProcessAfterInitialization
- bean constructor called
- bean setters called
- postProcessBeforeInitialization() method called for each BeanPostProcessor
- bean @PostConstruct method(s) called
- if bean implements InitializingBean, afterPropertiesSet() method called
- bean init-method called if configured
- postProcessAfterInitialization() method called for each BeanPostProcessor
Let's write some code to illustrate this:
TestBean.java
package com.example; import org.springframework.beans.factory.InitializingBean; import javax.annotation.PostConstruct; public class TestBean implements InitializingBean { private String text; public TestBean() { System.out.println("constructor"); } public void setText(String text) { System.out.println("setter"); this.text = text; } @PostConstruct public void postConstructInitialisation() throws Exception { System.out.println("postConstructInitialisation"); } @Override public void afterPropertiesSet() throws Exception { System.out.println("afterPropertiesSet"); } public void init() { System.out.println("init"); } }
TestBeanPostProcessor.java
package com.example; import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanPostProcessor; public class TestBeanPostProcessor implements BeanPostProcessor { @Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { System.out.println("TestBeanPostProcessor postProcessBeforeInitialization"); return bean; } @Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { System.out.println("TestBeanPostProcessor postProcessAfterInitialization"); return bean; } }
application-context.xml (snippet)
<bean class="com.example.TestBeanPostProcessor"> <bean class="com.example.TestBean" init-method="init"> <property name="text" value="Hello"/> </bean>
output:
constructor
setter
TestBeanPostProcessor postProcessBeforeInitialization
postConstructInitialisation
afterPropertiesSet
init
TestBeanPostProcessor postProcessAfterInitialization
Subscribe to:
Posts (Atom)