SPRING-MVC environment Construction of web framework

Source: Internet
Author: User
Tags db2 driver

1. Create a new Web project and join the spring MVC servlet in XML

<!--definition of Spring MVC container and servlet--  <servlet>    <servlet-name>springMVC</servlet-name>    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>    <!-- If this parameter is not configured, the default lookup is Web-inf under {servlet-name}-servlet.xml file-    <init-param>        <param-name> Contextconfiglocation</param-name>        <param-value>/WEB-INF/springMVC.xml</param-value>    </init-param>    <load-on-startup>1</load-on-startup>  </servlet>  < servlet-mapping>    <servlet-name>springMVC</servlet-name>    <url-pattern>/</ Url-pattern>  </servlet-mapping>

2. Join Spring MVC's Dependency jar package

Note: I have added some other features (quartz, hibernate implementation of JSR303, C3P0 connection pool, DB2 driver, Spring JSON support (Jackson)) In addition to the Spring jar package. The spring package is not fully included here, and the jar can be added or subtracted depending on the project's needs.

3. Configure the Spring MVC configuration file.

1<?xml version= "1.0" encoding= "UTF-8"?>2<beans xmlns= "Http://www.springframework.org/schema/beans"3Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"4xmlns:tx= "Http://www.springframework.org/schema/tx"5xmlns:context= "Http://www.springframework.org/schema/context"6xmlns:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"7Xmlns:mvc= "Http://www.springframework.org/schema/mvc"8xmlns:task= "Http://www.springframework.org/schema/task"9Xsi:schemalocation= "Http://www.springframework.org/schema/beansTenhttp//www.springframework.org/schema/beans/spring-beans-4.0.xsd Onehttp//Www.springframework.org/schema/tx Ahttp//www.springframework.org/schema/tx/spring-tx-4.0.xsd -http//Www.springframework.org/schema/context -http//www.springframework.org/schema/context/spring-context-4.0.xsd thehttp//WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP -http//www.springframework.org/schema/aop/spring-aop-4.0.xsd -http//Www.springframework.org/schema/mvc -http//www.springframework.org/schema/mvc/spring-mvc-4.0.xsd +http//Www.springframework.org/schema/task -http//www.springframework.org/schema/task/spring-task-4.0.xsd "> +  A<!--Spring MVC configuration-- at<context:annotation-config/> -<!--scanning Notes-- -<context:component-scan base- Package= "COM.TF"/> -<!--default MVC annotation Map Support-- -<mvc:annotation-driven/> -<!--supports asynchronous method execution-- in<task:annotation-driven/> -  to<!--View Parser and JSON parser-- +<beanclass= "Org.springframework.web.servlet.view.ContentNegotiatingViewResolver" > -<property name= "MediaTypes" > the<map> *<entry key= "html" value= "text/html"/> $<entry key= "JSON" value= "Application/json"/>Panax Notoginseng</map> -</property> the<property name= "Viewresolvers" > +<list> A<beanclass= "Org.springframework.web.servlet.view.InternalResourceViewResolver" > the<property name= "prefix" value= "/web-inf/jsp/"/> <!--can be empty, easy to implement their own based on the extension to select the View Interpretation class logic-- +<property name= "suffix" value= ". jsp"/> -</bean> $</list> $</property> -<property name= "Defaultviews" > -<list> the<beanclass= "Org.springframework.web.servlet.view.json.MappingJackson2JsonView"/> -</list>Wuyi</property> the</bean> -      Wu<!--file Upload parser-- -<bean id= "Multipartresolver" About         class= "Org.springframework.web.multipart.commons.CommonsMultipartResolver" > $<!--one of the properties available; The maximum file size in bytes-- -<property name= "Maxuploadsize" value= "-1"/> -</bean> -  A<!--total error Handling-- +<bean id= "Exceptionresolver" the         class= "Org.springframework.web.servlet.handler.SimpleMappingExceptionResolver" > -<property name= "Defaulterrorview" > $<value>/error</value> the</property> the<property name= "Defaultstatuscode" > the<value>500</value> the</property> -<property name= "Warnlogcategory" > in<value>Org.springframework.web.servlet.handler.SimpleMappingExceptionResolver the</value> the</property> About</bean> the  the<!--access to static resource files-- the<mvc:resources mapping= "/images/**" location= "/images/" cache-period= "31556926"/> +<mvc:resources mapping= "/js/**" location= "/js/" cache-period= "31556926"/> -<mvc:resources mapping= "/css/**" location= "/css/" cache-period= "31556926"/> the Bayi  the<!--database and transaction configuration-- the  -<!--load configuration files-- -<context:property-placeholder location= "Classpath:jdbc.properties"/> the<!--defining data sources-- the<bean id= "DataSource"class= "Com.mchange.v2.c3p0.ComboPooledDataSource" thedestroy-method= "Close" > the<property name= "Driverclass" > -<value>${jdbc.driverClass}</value> the</property> the<property name= "Jdbcurl" > the<value>${jdbc.url}</value>94</property> the<property name= "User" > the<value>${jdbc.username}</value> the</property>98<property name= "Password" > About<value>${jdbc.password}</value> -</property>101<!--the minimum number of connections that are kept in the connection pool. -102<property name= "Minpoolsize" >103<value>${c3p0.minPoolSize}</value>104</property> the<!--The maximum number of connections that are kept in the connection pool. Default:15--106<property name= "Maxpoolsize" >107<value>${c3p0.maxPoolSize}</value>108</property>109<!--the number of connections obtained when initializing, the value should be between Minpoolsize and Maxpoolsize. Default:3-- the<property name= "Initialpoolsize" >111<value>${c3p0.initialPoolSize}</value> the</property>113<!--check for idle connections in all connection pools every 30 seconds. Default:0-- the<property name= "Idleconnectiontestperiod" > the<value>${c3p0.idleConnectionTestPeriod}</value> the</property>117</bean>118<!--WebLogic recommend using Jndi Connection pool--119<!-- -<bean id= "DataSource"class= "Org.springframework.jndi.JndiObjectFactoryBean" >121<property name= "Jndiname" >122<value>java:comp/env/jdbc/myDatasource</value>123</property>124</bean> the-126 127<!--definition JdbcTemplate-- -<bean id= "JdbcTemplate"class= "Org.springframework.jdbc.core.JdbcTemplate" >129<property name= "DataSource" > the<ref bean= "DataSource"/>131</property> the</bean>133<bean id= "Namedparameterjdbctemplate"class= "Org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate" >134<constructor-arg><ref bean= "DataSource"/></constructor-arg>135</bean>136 137<!--define transaction manager--138<bean id= "TransactionManager"139         class= "Org.springframework.jdbc.datasource.DataSourceTransactionManager" > $<property name= "DataSource" >141<ref bean= "DataSource"/>142</property>143</bean>144 145<!--Configure transaction features, configure the method for add, delete, and update start, transaction propagation characteristics required--146<tx:advice id= "Txadvice" transaction-manager= "TransactionManager" >147<tx:attributes>148<tx:method name= "save*" propagation= "REQUIRED"/>149<tx:method name= "insert*" propagation= "REQUIRED"/> Max<tx:method name= "delete*" propagation= "REQUIRED"/>151<tx:method name= "update*" propagation= "REQUIRED"/> the<tx:method name= "login*" propagation= "REQUIRED"/>153<tx:method name= "regist*" propagation= "REQUIRED"/>154<tx:method name= "*" read-only= "true"/>155</tx:attributes>156</tx:advice>157 158<!--Configure the methods of those classes for transaction management--159<aop:config> the<aop:pointcut id= "Allmanagermethod" expression= "Execution (* com.tf.*.service.*.* (..))"/>161<aop:advisor advice-ref= "Txadvice" pointcut-ref= "Allmanagermethod"/>162</aop:config>163</beans>

SPRING-MVC environment Construction of web framework

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.