web配置
阿新 • • 發佈:2017-10-18
web
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1" metadata-complete="true"> <display-name>ms</display-name> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring-back.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <filter> <filter-name>encodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <servlet> <servlet-name>springMVC</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:/spring-servlet.xml</param-value> </init-param> <load-on-startup>2</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springMVC</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <servlet> <servlet-name>DruidStatView</servlet-name> <servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.css</url-pattern> <url-pattern>*.js</url-pattern> <url-pattern>*.ico</url-pattern> <url-pattern>*.swf</url-pattern> <url-pattern>*.gif</url-pattern> <url-pattern>*.jpeg</url-pattern> <url-pattern>*.bmp</url-pattern> <url-pattern>*.psd</url-pattern> <url-pattern>*.jpg</url-pattern> <url-pattern>*.png</url-pattern> <url-pattern>*.htm</url-pattern> <url-pattern>*.html</url-pattern> <url-pattern>*.xpi</url-pattern> <url-pattern>*.exe</url-pattern> <url-pattern>*.apk</url-pattern> <url-pattern>*.otf</url-pattern> <url-pattern>*.woff</url-pattern> <url-pattern>*.woff2</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>DruidStatView</servlet-name> <url-pattern>/druid/*</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>/login.jsp</welcome-file> </welcome-file-list> </web-app> ---------------------------------------------------- <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <mvc:default-servlet-handler/> <mvc:annotation-driven> <mvc:message-converters> <ref bean="marshallingHttpMessageConverter"/> <bean class="org.springframework.http.converter.StringHttpMessageConverter"> <constructor-arg value="UTF-8"/> </bean> <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>application/json</value> <value>application/xml</value> <value>text/html</value> <value>text/plain</value> <value>text/xml</value> </list> </property> <property name="fastJsonConfig" ref="fastJsonConfig"/> </bean> </mvc:message-converters> </mvc:annotation-driven> <context:component-scan base-package="com.lavasoft.*"/> <bean name="fastJsonConfig" class="com.alibaba.fastjson.support.config.FastJsonConfig"> <property name="serializerFeatures"> <list> <!-- 輸出key時是否使用雙引號 --> <value>QuoteFieldNames</value> <!-- 是否輸出值為null的字段 --> <!-- <value>WriteMapNullValue</value> --> <!-- 數值字段如果為null,輸出為0,而非null --> <!--<value>WriteNullNumberAsZero</value>--> <!-- List字段如果為null,輸出為[],而非null --> <value>WriteNullListAsEmpty</value> <!-- 字符類型字段如果為null,輸出為"",而非null --> <value>WriteNullStringAsEmpty</value> <!-- Boolean字段如果為null,輸出為false,而非null --> <value>WriteNullBooleanAsFalse</value> <!-- null String也要輸出 --> <!-- <value>WriteMapNullValue</value> --> <value>SortField</value> <value>WriteDateUseDateFormat</value> <value>PrettyFormat</value> <value>DisableCircularReferenceDetect</value> </list> </property> <property name="charset" value="UTF-8"/> <property name="dateFormat" value="yyyy-MM-dd HH:mm:ss"/> </bean> <bean id="marshallingHttpMessageConverter" class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter"> <property name="marshaller" ref="castorMarshaller"/> <property name="unmarshaller" ref="castorMarshaller"/> </bean> <bean id="castorMarshaller" class="org.springframework.oxm.castor.CastorMarshaller"/> <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"> <property name="contentNegotiationManager"> <bean id="contentNegotiationManagerFactoryBean" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean"> <property name="defaultContentType" value="text/html"/> <property name="ignoreAcceptHeader" value="true"/> <property name="favorPathExtension" value="true"/> <property name="favorParameter" value="false"/> <property name="mediaTypes"> <map> <entry key="json" value="application/json"/> <entry key="xml" value="application/xml"/> <entry key="html" value="text/html"/> </map> </property> </bean> </property> <property name="viewResolvers"> <list> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/"/> <property name="suffix" value=".jsp"/> </bean> </list> </property> <property name="defaultViews"> <list> <bean class="com.alibaba.fastjson.support.spring.FastJsonJsonView"> <property name="fastJsonConfig" ref="fastJsonConfig"/> </bean> <bean class="org.springframework.web.servlet.view.xml.MarshallingView"> <property name="marshaller" ref="castorMarshaller"/> </bean> </list> </property> </bean> <!--文件上傳--> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="maxUploadSize" value="100000"/> </bean> </beans>
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns="http://www.springframework.org/schema/beans" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <context:component-scan base-package="com.lavasoft.*"/> <context:property-placeholder location="classpath:jdbc.properties"/> <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"> <property name="driverClassName" value="${jdbc.driverClassName}"/> <property name="url" value="${jdbc.url}"/> <property name="username" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/> <property name="filters" value="stat"/> <property name="maxActive" value="10"/> <property name="initialSize" value="1"/> <property name="maxWait" value="60000"/> <property name="minIdle" value="5"/> <property name="timeBetweenEvictionRunsMillis" value="60000"/> <property name="minEvictableIdleTimeMillis" value="300000"/> <property name="validationQuery" value="SELECT 1"/> <property name="testWhileIdle" value="true"/> <property name="testOnBorrow" value="false"/> <property name="testOnReturn" value="false"/> <property name="poolPreparedStatements" value="true"/> <property name="maxPoolPreparedStatementPerConnectionSize" value="50"/> </bean> <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate" lazy-init="false"> <property name="dataSource" ref="dataSource"/> </bean> <bean id="namedJdbcTemplate" class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate" lazy-init="false"> <constructor-arg ref="dataSource"/> </bean> <!-- 事務管理器配置,單數據源事務 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"/> </bean> <!-- 配置那些類的方法進行事務管理 --> <aop:aspectj-autoproxy/> <aop:config> <aop:pointcut id="executeService" expression="execution(* com.lavasoft.*.service.*SVImpl.*(..))"/> <aop:advisor pointcut-ref="executeService" advice-ref="txAdvice"/> </aop:config> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="select*" read-only="true"/> <tx:method name="count*" read-only="true"/> <tx:method name="*NT" read-only="true"/> <tx:method name="get*" read-only="true"/> <tx:method name="load*" read-only="true"/> <tx:method name="find*" read-only="true"/> <tx:method name="is*" read-only="true"/> <tx:method name="read*" read-only="true"/> <tx:method name="check*" read-only="true"/> <tx:method name="gen*" read-only="true"/> <tx:method name="list*" read-only="true"/> <tx:method name="sync*" read-only="true"/> <tx:method name="*" propagation="REQUIRED" rollback-for="Exception"/> </tx:attributes> </tx:advice> </beans>
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns="http://www.springframework.org/schema/beans" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <context:component-scan base-package="com.lavasoft.*"/> <!-- 啟用自動代理功能 --> <context:annotation-config/> <aop:aspectj-autoproxy proxy-target-class="true"/> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="mapperLocations" value="classpath*:com/lavasoft/**/mapper/*.xml" /> <property name="typeAliasesPackage" value="com.lavasoft.demo.entity"/> <property name="configuration"> <bean class="org.apache.ibatis.session.Configuration"> <property name="cacheEnabled" value="true"/> <property name="useGeneratedKeys" value="true"/> <property name="mapUnderscoreToCamelCase" value="true"/> </bean> </property> </bean> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.lavasoft.demo.mapper"/> <property name="markerInterface" value="com.lavasoft.framework.BaseMapper"/> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/> </bean> <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate" scope="prototype"> <constructor-arg index="0" ref="sqlSessionFactory"/> </bean> <import resource="classpath:spring-core.xml"/> </beans>
jdbc.driverClassName=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://localhost:3306/testdb?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC&zeroDateTimeBehavior=round&allowMultiQueries=true jdbc.username=root jdbc.password=leizm
本文出自 “熔 巖” 博客,謝絕轉載!
web配置