springMVC的配置文件处理controller层
spring配置文件处理service/dao层
1、ESProject
web.xml:
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <display-name>ProjectConsole</display-name> <description>Web UI</description> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:META-INF/spring/applicationContext*.xml</param-value> </context-param> <!-- springMVC --> <servlet> <servlet-name>servlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring/webmvc-config.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>servlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <!-- Creates the Spring Container shared by all Servlets and Filters <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> --> <!-- webapp do something --> <listener> <listener-class>com.myproject.common.listener.EsbInitListener</listener-class> </listener> <!-- filter --> <filter> <filter-name>CharacterEncodingFilter</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>CharacterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter> <filter-name>springSecurityFilterChain</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> </filter> <filter-mapping> <filter-name>springSecurityFilterChain</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter> <filter-name>httpMethodFilter</filter-name> <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class> </filter> <filter-mapping> <filter-name>httpMethodFilter</filter-name> <servlet-name>servlet</servlet-name> </filter-mapping> <!-- session time out setting --> <filter> <filter-name>SessionTimeOutFilter</filter-name> <filter-class>com.myproject.common.filter.SessionTimeOutFilter</filter-class> <init-param> <param-name>logout</param-name> <param-value>/WEB-INF/views/login.jsp</param-value> </init-param> </filter> <filter-mapping> <filter-name>SessionTimeOutFilter</filter-name> <url-pattern>*.html</url-pattern> </filter-mapping> <filter-mapping> <filter-name>SessionTimeOutFilter</filter-name> <url-pattern>*.htm</url-pattern> </filter-mapping> <filter-mapping> <filter-name>SessionTimeOutFilter</filter-name> <url-pattern>*.jsp</url-pattern> </filter-mapping> <filter-mapping> <filter-name>SessionTimeOutFilter</filter-name> <url-pattern>*.do</url-pattern> </filter-mapping> <filter-mapping> <filter-name>SessionTimeOutFilter</filter-name> <url-pattern>*.json</url-pattern> </filter-mapping> <!-- DWR --> <servlet> <description>dwr-invoker</description> <servlet-name>dwr-invoker</servlet-name> <servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class> <init-param> <param-name>classes</param-name> <param-value>com.myproject.common.dwr.AutoTestCaseEvent</param-value> </init-param> <init-param> <param-name>debug</param-name> <param-value>true</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>dwr-invoker</servlet-name> <url-pattern>/dwr/*</url-pattern> </servlet-mapping> <session-config> <session-timeout>30</session-timeout> </session-config> <!-- welcome list --> <welcome-file-list> <welcome-file>/WEB-INF/views/login.jsp</welcome-file> </welcome-file-list> <!-- 以下为FLEX --> <!-- Http Flex Session attribute and binding listener support --> <listener> <listener-class>flex.messaging.HttpFlexSession</listener-class> </listener> <!-- MessageBroker Servlet --> <servlet> <servlet-name>MessageBrokerServlet</servlet-name> <servlet-class>flex.messaging.MessageBrokerServlet</servlet-class> <init-param> <param-name>services.configuration.file</param-name> <param-value>/WEB-INF/flex/services-config.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>MessageBrokerServlet</servlet-name> <url-pattern>/messagebroker/*</url-pattern> </servlet-mapping> </web-app>
webmvc-config.xml:
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> <context:component-scan base-package="com.project.soa.light2esb"> <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" /> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" /> </context:component-scan> <!-- root mapping <mvc:view-controller path="/" view-name="index"/> --> <mvc:annotation-driven /> <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources --> <mvc:resources location="/, classpath:/META-INF/web-resources/" mapping="/resources/**" /> <mvc:interceptors> <bean class="org.springframework.web.servlet.theme.ThemeChangeInterceptor"/> <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" p:paramName="lang"/> </mvc:interceptors> <mvc:default-servlet-handler /> <bean class="org.springframework.context.support.ReloadableResourceBundleMessageSource" id="messageSource" p:basenames="WEB-INF/i18n/messages,WEB-INF/i18n/application" p:fallbackToSystemLocale="false"/> <bean class="org.springframework.context.support.ReloadableResourceBundleMessageSource" id="errorSource" p:basenames="WEB-INF/i18n/errors" p:fallbackToSystemLocale="false"/> <!-- Store preferred language configuration in a cookie --> <bean class="org.springframework.web.servlet.i18n.CookieLocaleResolver" id="localeResolver" p:cookieName="locale"/> <!-- Resolves localized <theme_name>.properties files in the classpath to allow for theme support --> <bean class="org.springframework.ui.context.support.ResourceBundleThemeSource" id="themeSource"> <property name="basenamePrefix" value="theme-" /> </bean> <!-- Store preferred theme configuration in a cookie --> <bean class="org.springframework.web.servlet.theme.CookieThemeResolver" id="themeResolver" p:cookieName="theme" p:defaultThemeName="default"/> <bean id="handlerExceptionResolver" class="com.project.vis.platform.web.servlet.mvc.support.PlatformHandlerExceptionResolver"/> <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"></bean> <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver"></bean> <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"></bean> <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory --> <bean id="contentNegotiatingViewResolver" class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"> <property name="order" value="#{T(org.springframework.core.Ordered).HIGHEST_PRECEDENCE}"/> <property name="mediaTypes"> <map> <entry key="html" value="text/html" /> <entry key="json" value="application/json" /> <entry key="xml" value="application/xml" /> <entry key="pdf" value="application/pdf" /> <entry key="xsl" value="application/vnd.ms-excel" /> </map> </property> </bean> <!-- <bean id="resourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="order" value="#{contentNegotiatingViewResolver.order+1}"/> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> <property name="prefix" value="/WEB-INF/views/" /> <property name="suffix" value=".jsp" /> </bean> --> <bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"> <property name="order" value="#{contentNegotiatingViewResolver.order+1}"/> <property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/> </bean> <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer"> <property name="definitions"> <list> <value>/WEB-INF/layouts/layouts.xml</value> <!-- Scan views directory for Tiles configurations --> <value>/WEB-INF/views/**/views.xml</value> </list> </property> </bean> </beans>
applicationContext.xml:
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <context:property-placeholder location="classpath*:META-INF/spring/*.properties"/> <!-- <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${database.driverClassName}"/> <property name="url" value="${database.url}"/> <property name="username" value="${database.username}"/> <property name="password" value="${database.password}"/> <property name="validationQuery" value="SELECT 1 FROM dual"/> </bean> --> <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName"> <value>java:/datasources/visesbdb</value> </property> </bean> <!-- config dynamicDataSource --> <bean id="dynamicDataSource" class="com.myproject.common.datasource.MutiDataSourceBean"> <property name="targetDataSources"> <map key-type="java.lang.String"> <entry value-ref="dataSource" key="dataSource"></entry> </map> </property> <property name="defaultTargetDataSource" ref="dataSource"></property> </bean> <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/> <!-- Hibernate SessionFactory --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dynamicDataSource"/> <property name="packagesToScan"> <list> <value>com.myproject.bean</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="connection.useUnicode">true</prop> <prop key="connection.characterEncoding">UTF-8</prop> <prop key="hibernate.dialect">${hibernate.dialect}</prop> <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop> <prop key="hibernate.show_sql">${hibernate.show_sql}</prop> <prop key="hibernate.format_sql">${hibernate.format_sql}</prop> <prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop> <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop> </props> </property> </bean> <!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"/> </bean> <tx:annotation-driven transaction-manager="transactionManager"/> <!-- Activates scanning of @Autowired --> <context:annotation-config/> <context:component-scan base-package="com.myproject"> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" /> </context:component-scan> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="maxUploadSize" value="10000000"/> </bean> <!-- proxy module --> <bean id="proxy" class="com.myproject.proxy.impl.comm.ProxyCreatorImpl"/> <bean id="route" class="com.myproject.proxy.impl.route.RouteCreatorImpl"/> </beans>
2、cld项目
web.xml:
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" metadata-complete="true" version="2.5"> <display-name>system-web</display-name> <session-config> <session-timeout>30</session-timeout> </session-config> <context-param> <param-name>webAppRootKey</param-name> <param-value>system-web.root</param-value> </context-param> <context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath*:/applicationContext.xml, classpath*:/applicationContext-imports.xml </param-value> </context-param> <context-param> <param-name>spring.profiles.default</param-name> <param-value>development</param-value> </context-param> <!-- listener --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <listener> <listener-class> org.springframework.web.context.request.RequestContextListener </listener-class> </listener> <!-- filter --> <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> <filter> <filter-name>openEntityManagerInViewFilter</filter-name> <filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class> </filter> <filter-mapping> <filter-name>openEntityManagerInViewFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter> <filter-name>shiroFilter</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> <init-param> <param-name>targetFilterLifecycle</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>shiroFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter> <filter-name>sitemeshFilter</filter-name> <filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class> </filter> <filter-mapping> <filter-name>sitemeshFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- MVC --> <servlet> <servlet-name>springServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring-mvc.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springServlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app>
spring-mvc.xml:
<?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/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"> <!-- 自动扫描且只扫描@Controller --> <context:component-scan base-package="com.project" use-default-filters="false"> <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/> <context:include-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"/> </context:component-scan> <mvc:interceptors> <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"></bean> <bean class="com.project.f10.system.controller.interceptor.PermissionResourceInterceptor"></bean> </mvc:interceptors> <bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver" /> <mvc:annotation-driven> <mvc:message-converters register-defaults="true"> <!-- 将StringHttpMessageConverter的默认编码设为UTF-8 --> <bean class="org.springframework.http.converter.StringHttpMessageConverter"> <constructor-arg value="UTF-8" /> </bean> <!-- 将Jackson2HttpMessageConverter的默认格式化输出设为true --> <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"> <property name="prettyPrint" value="true"/> <property name="supportedMediaTypes"> <list> <value>application/json;charset=UTF-8</value> <value>text/json;charset=UTF-8</value> </list> </property> </bean> </mvc:message-converters> </mvc:annotation-driven> <!-- 定义JSP文件的位置 --> <!-- <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/views/"/> <property name="suffix" value=".jsp"/> </bean> --> <bean id="contentNegotiatingViewResolver" class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"> <property name="order" value="#{T(org.springframework.core.Ordered).HIGHEST_PRECEDENCE}"/> <property name="mediaTypes"> <map> <entry key="html" value="text/html" /> <entry key="json" value="application/json" /> <entry key="text" value="text/json" /> <entry key="xml" value="application/xml" /> <entry key="pdf" value="application/pdf" /> <entry key="xsl" value="application/vnd.ms-excel" /> </map> </property> </bean> <bean id="resourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="order" value="#{contentNegotiatingViewResolver.order+1}"/> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> <property name="prefix" value="/jsp/" /> <property name="suffix" value=".jsp" /> </bean> <!-- 定义无需Controller的url<->view直接映射 redirect:--> <mvc:view-controller path="/" view-name="redirect:/login/success"/> <!-- 组件js文件位置 --> <mvc:resources location="classpath:/META-INF/web-resources/" mapping="/web-resources/**" cache-period="31556926"/> <!-- 容器默认的DefaultServletHandler处理 所有静态内容与无RequestMapping处理的URL--> <mvc:default-servlet-handler/> <!-- 将Controller抛出的异常转到特定View, 保持SiteMesh的装饰效果 --> <!-- <bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"> <property name="exceptionMappings"> <props> <prop key="java.lang.Throwable">common/error/error</prop> <prop key="java.lang.Exception">common/error/error</prop> <prop key="java.lang.RuntimeException">common/error/error</prop> </props> </property> <property name="statusCodes"> <props> <prop key="common/error/404">404</prop> <prop key="common/error/error">500</prop> </props> </property> </bean> --> </beans>
applicationContext.xml:
<?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:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd" default-lazy-init="true"> <description>Spring公共配置 </description> <!-- 使用annotation 自动注册bean, 并保证@Required、@Autowired的属性被注入 --> <context:component-scan base-package="com.project.**.dao, com.project.**.service, com.project.**.controller"> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/> <context:exclude-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"/> </context:component-scan> <!-- Spring Data Jpa配置 --> <jpa:repositories base-package="com.project.**.dao" transaction-manager-ref="transactionManager" entity-manager-factory-ref="entityManagerFactory"/> <!-- 使用annotation定义事务 --> <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" /> <!-- Jpa 事务配置 --> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory"/> </bean> <!-- Jpa Entity Manager 配置 --> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter"/> <property name="packagesToScan" value="com.project.**.entity"/> <property name="jpaProperties"> <props> <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop> <!--cache/ehcache-hibernate-local.xml --> <prop key="net.sf.ehcache.configurationResourceName">cache/ehcache.xml</prop> <prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy</prop> <prop key="hibernate.show_sql">${hibernate.show_sql}</prop> <prop key="hibernate.format_sql">${hibernate.format_sql}</prop> <prop key="hibernate.cache.use_query_cache">true</prop> </props> </property> </bean> <bean id="hibernateJpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> <property name="databasePlatform"> <bean factory-method="getDialect" class="com.project.modules.persistence.Hibernates"> <constructor-arg ref="dataSource"/> </bean> </property> </bean> <!-- JSR303 Validator定义 --> <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" > <property name="validationMessageSource" ref="messageSource"/> <property name="providerClass" value="org.hibernate.validator.HibernateValidator"/> </bean> <!-- 国际化文件配制,查找当前classpath以及jar包中的classpath,以第一个加载的属性KEY为主 --> <bean id="messageSource" class="com.project.f10.common.utils.ReloadableResourceBundleMessageSource"> <property name="fileEncodings" value="utf-8"/> <property name="basenames"> <list> <value>classpath*:i18n/messages*</value> </list> </property> <!-- 为flase 消息code必须存在,否则会抛出异常 如果为true,目前会导致validateMessages中的消息不能格式化 --> <property name="useCodeAsDefaultMessage" value="false"/> </bean> <!-- 加载所有的配制文件 --> <!-- <context:property-placeholder location="classpath*:conf/*.properties" ignore-unresolvable="true"/> <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> <property name="basenames"> <list> <value>i18n/messages</value> <value>i18n/messages_tips</value> <value>i18n/messages_operation_log</value> </list> </property> <property name="useCodeAsDefaultMessage" value="true"/> </bean> --> <!-- production环境 --> <beans profile="production"> <context:property-placeholder ignore-unresolvable="true" location="classpath*:/application.properties, classpath*:conf/*-config.properties" /> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass" value="${datasource.driverClassName}" /> <property name="jdbcUrl" value="${datasource.url}" /> <property name="user" value="${datasource.username}" /> <property name="password" value="${datasource.password}" /> <property name="acquireIncrement" value="${c3p0.acquireIncrement}" /> <property name="initialPoolSize" value="${c3p0.initialPoolSize}" /> <property name="minPoolSize" value="${c3p0.minPoolSize}" /> <property name="maxPoolSize" value="${c3p0.maxPoolSize}" /> <property name="maxIdleTime" value="${c3p0.maxIdleTime}" /> <property name="idleConnectionTestPeriod" value="${c3p0.idleConnectionTestPeriod}" /> <property name="maxStatements" value="${c3p0.maxStatements}" /> <property name="numHelperThreads" value="${c3p0.numHelperThreads}" /> </bean> </beans> <!-- local development环境 --> <beans profile="development"> <context:property-placeholder ignore-resource-not-found="true" location="classpath*:/application.properties, classpath*:/application.development.properties, classpath*:/conf/*.development.properties " /> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass" value="${datasource.driverClassName}" /> <property name="jdbcUrl" value="${datasource.url}" /> <property name="user" value="${datasource.username}" /> <property name="password" value="${datasource.password}" /> <property name="acquireIncrement" value="${c3p0.acquireIncrement}" /> <property name="initialPoolSize" value="${c3p0.initialPoolSize}" /> <property name="minPoolSize" value="${c3p0.minPoolSize}" /> <property name="maxPoolSize" value="${c3p0.maxPoolSize}" /> <property name="maxIdleTime" value="${c3p0.maxIdleTime}" /> <property name="idleConnectionTestPeriod" value="${c3p0.idleConnectionTestPeriod}" /> <property name="maxStatements" value="${c3p0.maxStatements}" /> <property name="numHelperThreads" value="${c3p0.numHelperThreads}" /> </bean> </beans> <!-- functional test 环境 --> <beans profile="functional"> <context:property-placeholder ignore-resource-not-found="true" location="classpath*:/application.properties, classpath*:/application.functional.properties, classpath*:/conf/*.functional.properties" /> <!-- Tomcat JDBC连接池 --> <bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource" destroy-method="close"> <property name="driverClassName" value="${jdbc.driver}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> <property name="defaultAutoCommit" value="false" /> </bean> <!-- 初始化数据表结构 --> <!-- <jdbc:initialize-database data-source="dataSource" ignore-failures="ALL"> <jdbc:script location="classpath*:sql/${db.type}/schema.sql" encoding="UTF-8"/> <jdbc:script location="classpath*:sql/${db.type}/views.sql" encoding="UTF-8"/> <jdbc:script location="classpath*:sql/${db.type}/data/import-data.sql" encoding="UTF-8"/> </jdbc:initialize-database> --> </beans> <!-- unit test环境 --> <beans profile="test"> <context:property-placeholder ignore-resource-not-found="true" location="classpath*:/application.test.properties, classpath*:/conf/*.test.properties " /> <!-- Spring Simple连接池 --> <bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource"> <property name="driverClass" value="${jdbc.driver}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> </bean> </beans> <!-- standalone环境 --> <beans profile="standalone"> <context:property-placeholder ignore-resource-not-found="true" location="classpath*:/application.properties, classpath*:/application.standalone.properties, classpath*:/conf/*.standalone.properties" /> <!-- Spring Simple连接池 --> <bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource"> <property name="driverClass" value="${jdbc.driver}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> </bean> </beans> </beans>
3、老项目
WEB.xml:
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>svm</display-name> <!-- Hibernate延时加载 --> <filter> <filter-name>OpenSessionInViewFilter</filter-name> <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> </filter> <filter-mapping> <filter-name>OpenSessionInViewFilter</filter-name> <url-pattern>*.do</url-pattern> </filter-mapping> <filter-mapping> <filter-name>OpenSessionInViewFilter</filter-name> <url-pattern>*.json</url-pattern> </filter-mapping> <!-- Spring配置 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath:applicationContext.xml, classpath:applicationContext-service.xml, classpath:applicationContext-job.xml </param-value> </context-param> <!-- 应用监听器 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- session超时监控 --> <filter> <filter-name>SessionTimeOutFilter</filter-name> <filter-class> com.zte.soa.framework.common.filter.SessionTimeOutFilter </filter-class> <init-param> <param-name>logout</param-name> <param-value>/uiloader/forward.html</param-value> </init-param> </filter> <filter-mapping> <filter-name>SessionTimeOutFilter</filter-name> <url-pattern>*.html</url-pattern> </filter-mapping> <filter-mapping> <filter-name>SessionTimeOutFilter</filter-name> <url-pattern>*.htm</url-pattern> </filter-mapping> <filter-mapping> <filter-name>SessionTimeOutFilter</filter-name> <url-pattern>*.jsp</url-pattern> </filter-mapping> <filter-mapping> <filter-name>SessionTimeOutFilter</filter-name> <url-pattern>*.do</url-pattern> </filter-mapping> <!-- 字符编码 --> <filter> <filter-name>encoding</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>encoding</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- Spring MVC --> <servlet> <servlet-name>mvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext-mvc.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>mvc</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>mvc</servlet-name> <url-pattern>*.json</url-pattern> </servlet-mapping> <!-- 验证码 --> <servlet> <servlet-name>ValidationCode</servlet-name> <servlet-class>com.zte.soa.framework.ValidationCode</servlet-class> </servlet> <servlet-mapping> <servlet-name>ValidationCode</servlet-name> <url-pattern>/image/code.jpg</url-pattern> </servlet-mapping> <!-- session 超时 默认30分钟 --> <session-config> <session-timeout>30</session-timeout> </session-config> <welcome-file-list> <welcome-file>uiloader/login.html</welcome-file> </welcome-file-list> </web-app>
applicationContext-mvc.xml:
<?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-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd" default-lazy-init="false" default-autowire="byName"> <!-- 配置静态资源,直接映射到对应的文件夹,不被DispatcherServlet处理 --> <mvc:resources mapping="/js/**" location="/js/" /> <mvc:resources mapping="/css/**" location="/css/" /> <!-- 扫描Controller包 --> <context:component-scan base-package="com.zte.soa.common" /> <context:component-scan base-package="com.zte.soa.servmanagement" /> <context:component-scan base-package="com.zte.soa.system" /> <context:component-scan base-package="com.zte.soa.menu.controller" /> <context:component-scan base-package="com.zte.soa.login.controller" /> <!-- 处理@RequestMapping注解,类级别和方法级别 --> <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" /> <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> <property name="messageConverters"> <list> <ref bean="mappingJacksonHttpMessageConverter" /> </list> </property> </bean> <bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>application/json;charset=UTF-8</value> </list> </property> </bean> <!-- 视图解析 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/" /> <property name="suffix" value=".html" /> </bean> <!-- 这里申明的id必须为multipartResolver --> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="maxUploadSize" value="10000000"/> </bean> </beans>
配置2、
<servlet> <servlet-name>servlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring/webmvc-config.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>servlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:META-INF/spring/applicationContext*.xml</param-value> </context-param>
..
相关推荐
**SourceInsight 4.0配置文件详解** SourceInsight是一款强大的源代码分析和编辑工具,尤其在编程语言如C/C++、Java、C#等领域中广泛应用。它提供了高效的代码浏览、查找、编辑和理解功能,是软件开发人员提高工作...
INI 配置文件的保存和读取 INI 配置文件是一种常见的文件格式,用于存储程序的配置信息。它是一种简单的持久化机制,允许程序在启动时初始化配置信息。INI 文件由多个节(Section)组成,每个节中可以有多个键名...
**SourceInsight 4 风格配置文件详解** SourceInsight 4 是一款深受程序员喜爱的源代码分析和编辑工具,它提供了强大的代码浏览、查找、跳转和编辑功能。在SourceInsight中,用户可以根据个人喜好和工作需求定制...
在Android开发中,读写配置文件是常见的任务,主要用于存储应用程序的设置、用户偏好或者其他持久化数据。配置文件通常以XML或JSON格式存在,因为它们结构清晰,易于解析。本实例将详细介绍如何在Android中进行读取...
在IT行业中,配置文件是应用程序运行的关键组成部分,它们包含了各种设置和参数,用于定义系统的行为、连接数据库、控制权限等。"配置文件jar包"是一个集合,它将多个配置文件和必要的Java档案(jar文件)整合在一起...
标题中的“proe config配置文件大全”指的是针对Pro/Engineer Wildfire 5.0(简称ProE 5.0)软件的一系列配置文件集合。ProE是一款由PTC公司开发的三维参数化建模软件,广泛应用于产品设计和工程领域。配置文件是...
在Spring Boot应用中,多模块配置文件的读取是一个重要的实践,它有助于提高代码的可维护性和模块化。本文将详细探讨如何在Spring Boot的多模块项目中管理和使用不同的配置文件,以实现低耦合的设计。 首先,了解...
在C#编程中,Windows Forms(Winform)应用程序经常需要与配置文件进行交互,以便存储和检索应用设置。本文将详细讲解如何在Winform中读取和修改配置文件,特别是`appSettings`部分,这对于大多数桌面应用来说是至关...
在C#编程中,配置文件是用于存储应用程序运行时所需的设置和参数的重要工具。这些设置可以包括数据库连接字符串、API密钥、应用路径等。本教程将深入探讨如何使用C#进行配置文件的读写操作,并提供源代码供学习者...
在Linux系统中,C语言作为底层编程的主要工具,其对配置文件的操作往往涉及到繁琐的文件I/O操作。然而,为了简化这一过程,开发者通常会利用特定的库来处理配置文件,比如读取、写入、解析键值对等。本文将深入探讨...
vSphere 主机配置文件是VMware vSphere虚拟化平台的一个重要组成部分,它允许IT管理员创建、管理和应用配置文件来标准化和自动化vCenter Server中的ESXi主机配置。使用vSphere主机配置文件可以提高效率并减少重复...
标题中的“Hikvision配置文件解码器.zip”指出,这是一个与解码Hikvision视频监控设备配置文件相关的工具或程序。Hikvision是全球知名的安防监控设备制造商,其产品广泛应用于各种场所,如家庭、商业设施、公共安全...
本文将详细讲解海康威视配置文件解码的专业知识,以及如何利用“海康威视配置文件解码专用工具器”进行操作。 首先,了解什么是配置文件。在海康威视的设备中,配置文件通常包含了摄像头、NVR(网络视频录像机)或...
标题中的“笔记本颜色配置文件”指的是用于调整笔记本电脑显示屏色彩特性的ICC(International Color Consortium)配置文件。这种文件能够帮助用户校正显示器的色彩表现,确保显示的图像颜色与实际色彩更加接近,...
在LabVIEW中,配置文件是用于存储应用程序设置、参数或状态的关键元素。这些文件通常以.ini或.xml格式存在,允许程序在运行时根据这些配置进行自定义行为。本教程将深入探讨如何在LabVIEW中进行配置文件的写入与读取...
在Linux系统中,C语言开发过程中,经常需要与配置文件打交道,进行读取和写入操作。配置文件通常用于存储程序的设置或用户偏好,使其能够根据不同的环境或需求进行定制。下面我们将深入探讨如何在C语言中实现对配置...
标题中的“MACBook颜色配置文件Apple-MAC-OS-Color LCD.rar”指的是为苹果MacBook设计的一种特定的颜色配置文件,这种文件通常以ICC(International Color Consortium)格式存在,用于优化显示器的色彩表现,确保...
"mac的颜色配置文件",也就是苹果的ICC(International Color Consortium)配色文件,是这个过程中的重要组成部分。 ICC配色文件是一种标准化的方式,用来描述显示器、打印机、扫描仪等设备如何解释和再现颜色。这些...
在Java开发中,配置文件是应用中不可或缺的一部分,它们通常包含系统设置、数据库连接信息、应用参数等。本文将深入探讨如何在Java中实现动态修改配置文件,同时解决中文字符编码问题,使得配置文件的读写更加高效和...
在C++编程中,处理配置文件通常是为了存储和读取应用程序的设置或用户偏好。ini文件是一种常见的配置文件格式,其结构简单,易于理解和操作。本文将深入探讨如何使用C++来读写ini配置文件,主要参考提供的"rwconfig....