Best Pratices and Tweaks in Spring FrameworkFrom WikiJava
Ganesh Gowtham's Website
SummaryIn this article we will see some best of practices that we can incorporate using theSpring Framework for the folks who had just crossed beginner level (or) who are very enthusiastic to know more @ younger age (Beginner) :-) What is Spring Framework1 Main Modules of Spring Framework2 Design patterns used in Spring Framework3 Usage of JNDI,JdbcTemplate,DelegatingActionProxy,JunitFor Junit which used AbstractTransactionalSpringContextTests api , Please refer my another article
AbstractTransactionalSpringContextTests Example <struts-config> ... <action-mappings> <action path="/searchWikiUser" type="org.springframework.web.struts.DelegatingActionProxy"> <forward name="success" path="/pages/displayWikiUsers.jsp" /> </action> ... </action-mappings> .... </struts-config> spring-persistence.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd" > <beans> <!-- data source --> <bean class="org.apache.commons.dbcp.BasicDataSource" id="wikiDataSource" destroy-method="close"> <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" /> <property name="url" value="jdbc:oracle:thin:@dbserver:portNO:dbName" /> <property name="username" value="scott" /> <property name="password" value="elephant" /> <property name="defaultAutoCommit" value="true" /> <property name="maxActive" value="30" /> </bean> <!-- jdbctemplate --> <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"> <property name="dataSource" ref="wikiDataSource" /> </bean> <!-- dao --> <bean id="wikiUserDao" class="com.jpratice.dao.WikiUserDao"> <property name="jdbcTemplate" ref="jdbcTemplate" /> </bean> </beans> spring-serivice.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd" > <beans> <bean id="wikiUserService" class="com.jpratice.service.WikiUserService"> <property name="wikiUserDao" ref="wikiUserDao" /> </bean> </beans> spring-presentation.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd" > <beans> <bean name="/searchWikiUser" class="com.jpratice.action.SearchWikiUsers"> <property name="wikiUserService" ref="wikiUserService" /> </bean> </beans> spring-jndi.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd" > <beans> <bean class="com.jpratice.bean.EnvBean" id="EnvBean"> <property name="deployedEnv"> <bean class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName" value="java:comp/env/deployedEnv" /> </bean> </property> <property name="deployedAppVersion"> <bean class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName" value="java:comp/env/deployedAppVersion" /> </bean> </property> </bean> </beans> </property> spring.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd" > <beans> <import resource="/spring_persistence.xml" /> <import resource="/spring_service.xml" /> <import resource="/spring_presentation.xml" /> <import resource="/spring_jndi.xml" /> </beans> 4 Importing the different Spring files for clean separation based on different layers5 Importing the properties file present in jar which is kept @ classpath6 Time taken by each method execution7 configuring the Struts ,Spring with tomcat context file8 ReferencesSpring Framework Facts about Best Pratices and Tweaks in Spring FrameworkRDF feed
|
