Quick tips for Assembly and build spring MVC projects after long time

After some months without creating new Eclipse project not using maven I had two problems and here I’m documenting that with the objective to do not more see this problem in front of me and trying to help someone with the same problem.

The first is when you build the project and the assembly doesn’t work fine, your deploy structure is not understood for the eclipse and as least one dependency is not found in runtime. You can try to resolve as follow:

Right click in project —> properties —> Deployment Assembly —> Add —> Java Build Path Entries —> Next —> select jar or library —> next —> finish.

The second is when you build a Spring MVC project in eclipse and and run it onto Servlet/jsp container and for some reason it doesn’t works. Maybe you need to check your spring configuration file and see if the follow ViewResolver are ok.

<bean id=”viewResolver”
class=”org.springframework.web.servlet.view.InternalResourceViewResolver”>
<property name=”prefix”>
<value>/WEB-INF/[your jsp directory or just WEB-INF]</value>
</property>
<property name=”suffix”>
<value>.jsp</value>
</property>
</bean>

This piece of xml set the viewresolver, it means, where and wich one extensions your view tier (jsp) will understand.

 

 

Spring Bean lifecycle in practice

spring-framework-core-27-728

If you are looking for some Spring lifecycle Bean information or if you want to understand how the Spring create the instances under the their scope here I describe step by step and you can download one project in this link with some classes what fi you run them you will see in the log the steps clearly:

  – The principal steps awares.
 – BeanPostProcessor, Before initialization.
 – PostConstruct.
 – InitializingBean.
 – init a Person (a Object).
 – BeanPostProcessor After Initialization.
 – PreDestroy.
 – Destroy.

slcb2

slcb1

When you run the main method in SpringTest1 class you will see this on log:

1 – BeanNameAware: Object Person has been Initialized. Makes the object aware of their bean name in a bean factory.

2 – ClassLoaderAware, parent class loader gives the class loader used by the present bean factory to load bean classes.

3 – BeanFactoryAware: Be aware of their owning BeanFactory.

** BeanPostProcessor, Before Initialization person one per Bean, Spring container init instantiating, configuring, and initializing Bean.

4 – @PostConstruct: Init method after properties are set

5 – InitializingBean: afterPropertiesSet

6 – Init a Person: initPerson, init a Person by init-method method in Bean by  default-init-method or

6 – Init a Person: default-init, Initializing bean: person Default called to initialize Bean. If init-method is setted in beans.xml  this method will be executed.

       <bean id=“person”
             class=“br.com.springframework.test.Person”
             init-method=“initPerson”>
             <property name=“name” value=“Felipe” />
       </bean>

** BeanPostProcessor After Initialization person one per Bean, Spring container finish instantiating, configuring, and initializing Bean
Method talk is executed: ** I said hello! **

Calling ConfigurableApplicationContext close()…
ov 10, 2015 4:14:14 PM org.springframework.context.support.ClassPathXmlApplicationContext doClose
INFORMAÇÕES: Closing org.springframework.context.support.ClassPathXmlApplicationContext@1f8302d: startup date [Tue Nov 10 16:14:13 BRST 2015]; root of context hierarchy

7 @PreDestroy: Spring Clean Up! Person is cleaned up now. (named via beans.xml)
8- DisposableBean destroy(): Released the bean: person Called after Spring container is released the bean.

Enjoy!