spring+springMVC+配置文件propertites

web.xml:

<listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>  <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            classpath*:/spring/applicationContext*.xml
        </param-value>
    </context-param>
    <context-param>
        <param-name>spring.profiles.default</param-name>
        <!-- 研发 <param-value>production</param-value>-->
        <param-value>iie_test</param-value> 
    </context-param>
     <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/spring-mvc.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>
    
    <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>
    
    <!-- SiteMesh Web-Page Layout filter -->
    <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>

    <session-config>
        <session-timeout>20</session-timeout>
    </session-config>

application.xml:

    <!-- 使用annotation 自动注册bean, 并保证@Required、@Autowired的属性被注入 -->
    <context:component-scan base-package="cn.ac.nercis.cloudtv.dal">
        <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>
    <!-- 开发库 -->
    <beans profile="production">
        <bean id="appConfig"
            class="org.springframework.beans.factory.config.PropertiesFactoryBean">
            <property name="locations">
                <list>
                    <value>classpath*:/props/prod/*.properties</value>
                </list>
            </property>
        </bean>
        <bean id="propertyConfigurer"
            class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
            <property name="properties" ref="appConfig" />
        </bean>
    </beans>
    
    <!-- 测试库 -->
    <beans profile="iie_test">
        <bean id="appConfig"
            class="org.springframework.beans.factory.config.PropertiesFactoryBean">
            <property name="locations">
                <list>
                    <value>classpath*:/props/iie_test/*.properties</value>
                </list>
            </property>
        </bean>
        <bean id="propertyConfigurer"
            class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
            <property name="properties" ref="appConfig" />
        </bean>
    </beans>

spring-mvc:

<?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="cn.ac.nercis.cloudtv.dal.controller" use-default-filters="true">
        <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>
    
    <bean class="com.mangofactory.swagger.configuration.DocumentationConfig" />
    <context:property-placeholder location="classpath*:/props/iie_test/swagger.properties" />
    
    <!-- 开启spring mvc -->
    <mvc:annotation-driven>
        <mvc:message-converters register-defaults="true">
            <bean
                class="org.springframework.http.converter.ByteArrayHttpMessageConverter" />
            <!-- 将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">
            </bean>
            
        </mvc:message-converters>
        <mvc:argument-resolvers>
            <bean
                class="org.springframework.data.web.PageableHandlerMethodArgumentResolver">
            </bean>
             <bean
                class="org.springframework.data.web.SortHandlerMethodArgumentResolver">
            </bean>
        </mvc:argument-resolvers>
    </mvc:annotation-driven>

    <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
        <property name="contentNegotiationManager">
            <bean class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
                <property name="ignoreAcceptHeader" value="true"/>
                <property name="defaultContentType" value="application/json"/>
                <property name="mediaTypes">
                    <map>
                        <entry key="html" value="text/html"/>
                        <entry key="json" value="application/json"/>
                    </map>
                </property>
            </bean>
        </property>
        <property name="defaultViews">
            <list>
                <bean class="org.springframework.web.servlet.view.json.MappingJackson2JsonView"/>
            </list>
        </property>
    </bean>
    
    <bean id="jspViewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/pages/" />
        <property name="suffix" value=".jsp" />
    </bean>
    
    <mvc:resources mapping="/static/**" location="/static/"/>
     <!-- 容器默认的DefaultServletHandler处理 所有静态内容与无RequestMapping处理的URL-->    
    <mvc:default-servlet-handler/>

</beans>

applicationContex-mongo.xml:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:cloud="http://schema.cloudfoundry.org/spring" xmlns:context="http://www.springframework.org/schema/context" xmlns:mongo="http://www.springframework.org/schema/data/mongo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd        http://www.springframework.org/schema/data/mongo        http://www.springframework.org/schema/data/mongo/spring-mongo-1.5.xsd        http://www.springframework.org/schema/beans        http://www.springframework.org/schema/beans/spring-beans-4.0.xsd        http://schema.cloudfoundry.org/spring http://schema.cloudfoundry.org/spring/cloudfoundry-spring-0.8.xsd">

  <mongo:mongo host="${mongo.host}" port="${mongo.port}">
  <mongo:options connections-per-host="10"
                   threads-allowed-to-block-for-connection-multiplier="5"
                   connect-timeout="10000"
                   max-wait-time="15000"
                   auto-connect-retry="true"
                   socket-keep-alive="true"
                   socket-timeout="15000"
                   slave-ok="true"
                   write-number="1"
                   write-timeout="0"
                   write-fsync="true"/>
</mongo:mongo>

<mongo:db-factory dbname="${mongo.database}" mongo-ref="mongo" username="${mongo.username}" password="${mongo.password}"/>

<mongo:repositories base-package="cn.ac.nercis.cloudtv.dal.repository"/>

<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
  <constructor-arg name="mongoDbFactory" ref="mongoDbFactory"/>
</bean>

<mongo:mapping-converter id="converter" />

  <bean class="org.springframework.data.mongodb.gridfs.GridFsTemplate">
    <constructor-arg ref="mongoDbFactory" />
    <constructor-arg ref="converter" />
  </bean>

</beans>

applicationContex-mysql.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" xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xmlns:tx="http://www.springframework.org/schema/tx"
    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/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-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/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd"
    default-lazy-init="true">

    <description>Spring数据库配置 </description>

    <!-- transaction manager, use JtaTransactionManager for global tx -->
    <bean id="transactionManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>

    <!-- enable transaction demarcation with annotations -->
    <tx:annotation-driven />

    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="configLocation" value="classpath:mybatis/configuration.xml" />
        <property name="mapperLocations">
            <list>
                <value>classpath*:cn/ac/nercis/cloudtv/dal/repository/mapper/*.xml</value>
            </list>
        </property>
    </bean>

    
    <!-- scan for mappers and let them be autowired -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    
        <property name="basePackage" value="cn.ac.nercis.cloudtv.dal.repository.mapper" />
        <!-- 如果不加下面这行,单独在Tomcat里启动时,Tomcat启动不了 -->
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
    </bean>

    <!-- 数据源配置, 使用Tomcat JDBC连接池 -->
     <bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource" destroy-method="close">
         <!-- Connection Info -->
        <property name="driverClassName" value="${jdbc.driver}" />
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
     
        <!-- Connection Pooling Info -->
        <property name="maxActive" value="${jdbc.pool.maxActive}" />
        <property name="maxIdle" value="${jdbc.pool.maxIdle}" />
        <property name="minIdle" value="0" />
        <property name="defaultAutoCommit" value="false" />
     </bean>
    
</beans>

mysql.properties:

mongo.database=pdp
mongo.host=10.10.104.16
mongo.password=
mongo.port=17017
mongo.username=

mongo.properties:

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://10.10.104.16:3306/cloudtv2?useUnicode=true&characterEncoding=utf-8
jdbc.username=root
jdbc.password=123456

#dbcp settings
jdbc.pool.maxIdle=5
jdbc.pool.maxActive=40
时间: 2024-10-30 07:11:18

spring+springMVC+配置文件propertites的相关文章

spring(一)--spring/springmvc/spring+hibernate(mybatis)配置文件

这篇文章用来总结一下spring,springmvc,spring+mybatis,spring+hibernate的配置文件 1.web.xml 要使用spring,必须在web.xml中定义分发器等信息,基本的配置信息如下: <?xml version="1.0" encoding= "UTF-8"?> <web-app version= "3.0" xmlns="http://java.sun.com/xml/n

Spring+SpringMVC+MyBatis深入学习及搭建(三)——MyBatis全局配置文件解析

转载请注明出处:http://www.cnblogs.com/Joanna-Yan/p/6874672.html 前面有写到Spring+SpringMVC+MyBatis深入学习及搭建(二)——MyBatis原始Dao开发和mapper代理开发 MyBatis的全局配置文件SqlMapConfig.xml,配置内容和顺序如下: properties(属性) setting(全局配置参数) typeAliases(类名别名) typeHandlers(类名处理器) objectFactory(对

Spring+SpringMVC +MyBatis整合配置文件案例66666

Spring+SpringMVC +MyBatis整合配置文件案例 标签: springspringmvcmybatismvcjava 2017-04-13 19:12 228人阅读 评论(1) 收藏 举报 分类: java_javaSE(2) 版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[+] Spring+SpringMVC +MyBatis整合配置文件案例 针对spring/SpringMVC/MyBatis三个框架的整合有很多的方式,经过最近的学习我来总结一下其配置文

SSM:spring+springmvc+mybatis框架中的XML配置文件功能详细解释

SSM:spring+springmvc+mybatis框架中的XML配置文件功能详细解释 2016-04-14 23:40 13030人阅读 评论(2) 收藏 举报 分类: SSM(7) 这几天一直在整合SSM框架,虽然网上有很多已经整合好的,但是对于里面的配置文件并没有进行过多的说明,很多人知其然不知其所以然,经过几天的搜索和整理,今天总算对其中的XML配置文件有了一定的了解,所以拿出来一起分享一下,希望有不足的地方大家批评指正~~~ 首先   这篇文章暂时只对框架中所要用到的配置文件进行解

Spring+SpringMVC重复加载配置文件问题

sping+springmvc的框架中,IOC容器的加载过程 http://my.oschina.net/xianggao/blog/596476 基本上是先加载ContextLoaderListener,然后生成一个ioc容器. 然后再实例化DispatchServlet时候在加载对应的配置文件,再次生成Controller相关的IOC容器 关于上面两个容器关系: ContextLoaderListener中创建ApplicationContext主要用于整个Web应用程序需要共享的一些组件,

spring+springmvc+mybatis配置文件

最近在学习SSM,自己上手了一个crm项目,这两天对底层配置文件做了个总结. sqlmapconfig.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd&qu

基于Spring+SpringMVC+Mybatis的Web系统搭建

主要的后端架构:Spring+SpringMVC+Mybatis+Shiro+Maven  IDE:IntelliJ IDEA 15.0.2 jdk:1.8.0_66 系统完整源码 https://github.com/Wellat/Factor 系统目录结构 跑起来效果 搭建步骤 1.用Idea创建maven项目 2.配置pom.xml文件,添加依赖 1 <?xml version="1.0" encoding="UTF-8"?> 2 <proj

SSM框架 (Spring+SpringMVC+MyBatis)

SSM框架--详细整合教程(Spring+SpringMVC+MyBatis) springspringmvcmybatis整合教程ssm整合 1.基本概念  1.1.Spring          Spring是一个开源框架,Spring是于2003 年兴起的一个轻量级的Java 开发框架,由Rod Johnson 在其著作Expert One-On-One J2EE Development and Design中阐述的部分理念和原型衍生而来.它是为了解决企业应用开发的复杂性而创建的.Spri

SSM框架整合(Spring+SpringMVC+MyBatis)

[SSM的系统架构] [整合概述] 第一步: MyBatis和Spring整合,通过Spring管理mapper接口. 使用mapper的扫描器自动扫描mapper接口在Spring中进行注册. 第二步: 通过Spring管理Service接口. 使用配置方式将Service接口配置在Spring配置文件中. 实现事务控制. 第三步: 由于SpringMVC是Spring的模块,无需整合这两个. [工程截图] [数据库的items] [ 表结构 ] [ 表内数据 ] [1.整合dao]将Myba