Spring Servlet Mapping XML All Cut point for my Spring Hiberntate Solution

June 15th, 2011
Comments Off

Content about : Spring Servlet Mapping XML
Advertisements


This XML is Configuration for all Cut point from View , Controller and Model in this XML is Contain
Bean mapping factory for Model Class , Interceptor  and Controller

Example Servlet XML Mapping for Spring Framework
<?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=”configurer” class=”org.springframework.beans.factory.config.PropertyPlaceholderConfigurer”>
<property name=”location” value=”file:/EnterprisePT/conf.properties”/>
</bean>

<bean id=”viewResolver” class=”org.springframework.web.servlet.view.InternalResourceViewResolver”>
<property name=”viewClass” value=”org.springframework.web.servlet.view.JstlView” />
<property name=”prefix” value=”/jsp/” />
<property name=”suffix” value=”.jsp” />
<property name=”contentType” value=”text/html; charset=UTF-8″ />
</bean>
<bean id=”urlMapping” class=”org.springframework.web.servlet.handler.SimpleUrlHandlerMapping”>
<property name=”interceptors”>
<list>
<ref local=”exampleInterceptor”/>
</list>
</property>
<property name=”mappings”>
<props>
<prop key=”/example_insert.html”>exampleController</prop>
<prop key=”/example_load.html”>exampleController</prop>
<prop key=”/example_delete.html”>exampleController</prop>
<prop key=”/example_ws.html”>exampleController</prop>
<prop key=”/example_sap.html”>exampleController</prop>
</props>
</property>
</bean>

<!– ========================= CONTROLLER DEFINITIONS ========================= –>
<bean id=”exampleController” class=”com.en.controller.ExampleController”>
<property name=”methodNameResolver” ref=”exampleControllerResolver”/>
<property name=”model” ref=”exampleModel”/>
<property name=”defaultScreen” value=”example”/>
</bean>
<bean id=”exampleControllerResolver” class=”org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver”>
<property name=”mappings”>
<props>
<prop key=”/example_insert.html”>insertMethod</prop>
<prop key=”/example_load.html”>loadMethod</prop>
<prop key=”/example_delete.html”>deleteMethod</prop>
<prop key=”/example_ws.html”>callWS</prop>
<prop key=”/example_sap.html”>callSAP</prop>
</props>
</property>
</bean>
<bean id=”exampleModel” class=”com.en.model.ExampleModel”>
<property name=”hibernateTemplate” ref=”hibernateTemplate”/>
<property name=”wsClient” ref=”exampleWSClient”/>
<property name=”sap” ref=”exampleSAP”/>
</bean>

<bean id=”exampleInterceptor” class=”com.en.interceptor.ExampleInterceptor” />
<bean id=”exampleWSClient” class=”com.en.ws.client.ExampleWSClient”>
<property name=”endpoint” value=”http://127.0.0.1:8080/EnterPrisePT/ws/example”/>
</bean>
<bean id=”exampleSAP” class=”com.en.sap.ExampleSAP” />

</beans>

admin Development , ,

Spring Datasource XML Example Configuration for Connect Database

June 15th, 2011
Comments Off

Content about : Spring Datasource XML
Advertisements


My solution guide for 2 solution in DBMS Connect  with JNDI and Direction Contect
Example for Spring Datasource 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=”propertyPlaceholder”
class=”org.springframework.beans.factory.config.PropertyPlaceholderConfigurer”>
<property name=”locations”>
<list>
<value>classpath*:db.properties</value>
</list>
</property>
</bean>
<!– For Direct Connection–>
<bean id=”dataSourceDirect”
class=”org.apache.commons.dbcp.BasicDataSource” destroy-method=”close” >
<property name=”driverClassName” value=”${db.driverClassName}”/>
<property name=”url” value=”${db.url}”/>
<property name=”username” value=”${db.username}”/>
<property name=”password” value=”${db.password}”/>
</bean>

<!–For JNDI
<bean id=”dataSourceJNDI”
class=”org.springframework.jndi.JndiObjectFactoryBean”>

<property name=”jndiName” value=”${db.jndi}” />
</bean>
–>
</beans>

Note : You can use connection pools  framework to mapping and use with Spring Framework

admin Development

Spring Hibernate XML Configuration

June 15th, 2011
Comments Off

Content about :  Spring Hibernate XML Configuration
Advertisements


After Create Mapping class my solution need to create XML configuration file to made Spring and Hibernate working together

Example XML Configuration for Spring Hibernate
<?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=”sessionFactory”
class=”org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean”>

<property name=”dataSource” ref=”dataSource” />
<property name=”hibernateProperties”>
<props>
<prop key=”hibernate.dialect”>${db.hibernate.dialect}</prop>
<prop key=”hibernate.show_sql”>false</prop>
<prop key=”hibernate.format_sql”>true</prop>
<prop key=”hibernate.default_batch_fetch_size”>0</prop>
<prop key=”hibernate.jdbc.batch_size”>0</prop>
<prop key=”hibernate.use_outer_join”>true</prop>
<prop key=”hibernate.max_fetch_depth”>2</prop>
<prop key=”hibernate.generate_statistics”>true</prop>
</props>
</property>
<property name=”configLocation”>
<value>classpath:hibernate.cfg.xml</value>
</property>
<property name=”lobHandler”>
<bean class=”org.springframework.jdbc.support.lob.DefaultLobHandler” />
</property>
</bean>

<bean id=”hibernateInterceptor” class=”org.springframework.orm.hibernate3.HibernateInterceptor”>
<property name=”sessionFactory”>
<ref bean=”sessionFactory” />
</property>
</bean>

<bean id=”hibernateTemplate” class=”org.springframework.orm.hibernate3.HibernateTemplate”>
<property name=”sessionFactory” ref=”sessionFactory” />
</bean>

</beans>

Note
** ${db.hibernate.dialect} is dialect to tell hibernate What’s is DBMS ? eg. org.hibernate.dialect.MySQLDialect
** classpath:hibernate.cfg.xml need to load  hibernate.cfg.xml to classpath  to tell this is Hibernate Mapping Class

Example for  hibernate.cfg.xml
<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE hibernate-configuration PUBLIC
“-//Hibernate/Hibernate Configuration DTD 3.0//EN”
“http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd”>
<hibernate-configuration>
<session-factory>
<mapping class=”com.en.hibernate.Example”/>
</session-factory>
</hibernate-configuration>

admin Development