Content about : Spring WEB.xml
Advertisements
After you made all of Class eg Hibernate ,DTO , Model ,Controller and made all of XML Configuration eg. Datasource XML ,Hibernate XML,Servlet XML you need to add all to Load it in WEB.xml Lest go to Start Spring Engine Now !!
Example Web.xml for Start Spring
<?xml version=”1.0″ encoding=”UTF-8″?>
<web-app id=”WebApp_ID” version=”2.4″
xmlns=”http://java.sun.com/xml/ns/j2ee” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xmlns:c=”http://java.sun.com/jsp/jstl/core”
xmlns:fmt=”http://java.sun.com/jsp/jstl/fmt”
xsi:schemaLocation=”http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd”>
<display-name>EnterprisePT</display-name>
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>EnterprisePT.root</param-value>
</context-param>
<!– log4j configuration in web.xml –>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<!– /log4j configuration in web.xml END –>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/appcontext/datasource-service.xml
/WEB-INF/appcontext/dataAccesssContext-Hibernate.xml
/WEB-INF/appcontext/view-servlet.xml
/WEB-INF/appcontext/applicationCfxContext-WS.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/ws/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>appcontext/view</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appcontext/view</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
Development
class-loading-behavior, proprietary-deployment-descriptors, Spring Hibernate
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>
Development
application-context, singleton, Spring Hibernate
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
Development
Spring Hibernate