pom.springmvc.psring-contect自用常用文件配置

-----------------------pom.xml--------------------------
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.xy</groupId>
  <artifactId>web-master</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>Management_Platform Maven Webapp</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>
  <dependencies>

    <!-- springMVC -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>5.1.6.RELEASE</version>
    </dependency>

    <dependency>
      <!-- jstl 支持 -->
      <groupId>javax.servlet</groupId>
      <artifactId>jstl</artifactId>
      <version>1.2</version>
    </dependency>
    <dependency>
      <!-- servlet编译环境 -->
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.1.0</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <!-- jsp编译环境 -->
      <groupId>javax.servlet</groupId>
      <artifactId>jsp-api</artifactId>
      <version>2.0</version>
      <scope>provided</scope>
    </dependency>

    <!-- FastJson -->
    <dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>fastjson</artifactId>
      <version>1.2.54</version>
    </dependency>

    <!-- Spring -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>5.1.6.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-aspects</artifactId>
      <version>5.1.6.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-test</artifactId>
      <version>5.1.6.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jdbc</artifactId>
      <version>5.1.6.RELEASE</version>
    </dependency>

    <!-- Spring整合mybatis -->
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis-spring</artifactId>
      <version>1.3.1</version>
    </dependency>

    <!-- MyBatis -->
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis</artifactId>
      <version>3.4.5</version>
    </dependency>

    <!-- mysql驱动 依赖 -->
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>5.1.25</version>
      <scope>runtime</scope>
    </dependency>

    <!-- 连接池 -->
    <dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>druid</artifactId>
      <version>1.1.12</version>
    </dependency>

    <!-- Junit -->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
    </dependency>

    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <version>2.9.6</version>
    </dependency>

    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
      <version>1.16.10</version>
    </dependency>

  </dependencies>

  <build>

    <!-- 更改maven编译规则 -->
    <resources>
      <resource>
        <!-- 资源目录 -->
        <directory>src/main/java</directory>
        <includes>
          <include>*.xml</include><!-- 默认(新添加自定义则失效) -->
          <include>**/*.xml</include><!-- 新添加 */代表1级目录 **/代表多级目录 -->
        </includes>
        <filtering>true</filtering>
      </resource>
    </resources>
-----------------------pom.xml--------------------------

-----------------------web.xml--------------------------
<?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_4_0.xsd"
         version="4.0">
  <display-name>Archetype Created Web Application</display-name>

  <!--配置核心控制器DispatcherServlet-->
  <servlet>
    <servlet-name>mvc</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <!--DispatcherServlet读取的配置文件的位置-->
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:springmvc.xml</param-value>
    </init-param>
    <!--服务启动就创建-->
    <load-on-startup>1</load-on-startup>
  </servlet>
  <!--拦截所有请求-->
  <servlet-mapping>
    <servlet-name>mvc</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
  <filter>
    <!--request.setCharacterEncoding("UTF-8")-->
    <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>
  </filter>
  <filter-mapping>
    <filter-name>encoding</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring-context.xml</param-value>
  </context-param>
</web-app>
-----------------------web.xml--------------------------


-----------------------spring-context.xml--------------------------
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                           http://www.springframework.org/schema/beans/spring-beans.xsd
                           http://www.springframework.org/schema/aop
                           http://www.springframework.org/schema/aop/spring-aop.xsd
                           http://www.springframework.org/schema/tx
                           http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
    <!--数据库配置信息文件的位置-->
    <context:property-placeholder location="classpath:db.properties"></context:property-placeholder>
    <!--原来在mybatis中配置连接池信息   整合后,拿到spring中配置-->
    <!--配置Druid连接池-->
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
          init-method="init" destroy-method="close">
        <!--通过设值注入给属性赋值-->
        <property name="driverClassName" value="${jdbc.driverClass}"/>
        <property name="url" value="${jdbc.url}"/>
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
        <!--初始化连接数量  最小空闲数量  最大活跃数量-->
        <property name="initialSize" value="${jdbc.init}"></property>
        <property name="minIdle" value="${jdbc.minIdle}"></property>
        <property name="maxActive" value="${jdbc.maxActive}"></property>
        <!--配置获取连接的超时的时间-->
        <property name="maxWait" value="60000"></property>
        <!--配置检查时间的间隔,检查需要关闭的空闲连接的时间间隔,单位ms-->
        <property name="timeBetweenEvictionRunsMillis" value="60000"></property>
        <!--配置连接池的最小生存时间-->
        <property name="minEvictableIdleTimeMillis" value="30000"></property>
    </bean>

    <!--创建mybatis操作数据库时需要的SqlSessionFactory-->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!--注入属性值-->
        <property name="dataSource" ref="dataSource"></property>
        <!--告知mybatis接口对应的映射文件的位置-->
        <property name="mapperLocations">
            <list>
                <value>classpath:com/xy/master/dao/*.xml</value>
            </list>
        </property>
        <!--配置实体类的别名-->
        <property name="typeAliasesPackage" value="com.xy.master.entity"></property>
    </bean>
    <!--配置MapperScannerConfigurer  在dao中通过此配置就可以得到sqlSession-->
    <bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <!--dao接口所在的包:如果接口在多个包中,可以使用都好进行分割-->
        <property name="basePackage" value="com.xy.master.dao"></property>
        <!--配置得到sqlSession需要的sqlSessionFactory
            [说明] 引入另外一个对象时,需要使用ref进行引入,但是此处通过value-->
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
    </bean>

    <!--创建事务管理器-->
    <bean id="tx" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <!--注入datasource属性-->
        <property name="dataSource" ref="dataSource"></property>
    </bean>

    <context:component-scan base-package="com.xy.master"></context:component-scan>
    <tx:annotation-driven transaction-manager="tx"></tx:annotation-driven>

    <aop:aspectj-autoproxy ></aop:aspectj-autoproxy>
</beans>
-----------------------spring-context.xml--------------------------


-----------------------springmvc.xml--------------------------
<?xml version="1.0" encoding="UTF-8" ?>
<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:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://www.springframework.org/schema/beans
							http://www.springframework.org/schema/beans/spring-beans.xsd
							http://www.springframework.org/schema/context
							http://www.springframework.org/schema/context/spring-context.xsd
							http://www.springframework.org/schema/mvc
							http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <!--SpringMVC扫描的父包:只扫描controller所在包即可-->
    <context:component-scan base-package="com.xy.master" use-default-filters="false">
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>

    <!--MVC注解驱动:MVC采用注解方式实现-->
    <mvc:annotation-driven>
        <!-- 安装FastJson,转换器 -->
        <mvc:message-converters>
            <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
                <!-- 声明转换类型:json -->
                <property name="supportedMediaTypes">
                    <list>
                        <value>application/json</value>
                    </list>
                </property>
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven>



    <!--配置 视图解析器:解析控制器方法返回的字符串所对应的视图位置-->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/"></property><!--到项目的根目录下寻找视图-->
        <property name="suffix" value=".jsp"></property><!--视图的扩展名-->
    </bean>
    <!--配置 异常解析器:捕获handler中的所有异常,跳转到对应的错误页面-->
    <!--<bean class="com.qf.springmvc.utils.MyExceptionResolver"></bean>-->

    <!--配置拦截器-->
    <!--<mvc:interceptors>
        <mvc:interceptor>
            <mvc:mapping path="/my/**"/>
            <mvc:exclude-mapping path="/my/a/**"/>
            <bean class="com.qf.springmvc.utils.MyInterceptor"></bean>
        </mvc:interceptor>
    </mvc:interceptors>
    -->
    <!--放行静态资源请求,到DefaultServlet中-->
    <mvc:default-servlet-handler/>
</beans>
-----------------------springmvc.xml--------------------------


jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/tb_openplatform?useUnicode=true&characterEncoding=UTF-8
jdbc.username=root
jdbc.password=lxy19970507
jdbc.init=1
jdbc.minIdle=1
jdbc.maxActive=3
  </build>
</project>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值