ssm配置

作者: laidian | 来源:发表于2016-10-10 16:54 被阅读109次

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_3_1.xsd"
         version="3.1"
         metadata-complete="true">

    <description>
        seckill system
    </description>
    <display-name>appname</display-name>

    <servlet>
        <servlet-name>seckill-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:spring-*.xml</param-value>
        </init-param>
    </servlet>

    <servlet-mapping>
        <servlet-name>seckill-dispatcher</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>
    </filter>
    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>/</url-pattern>
    </filter-mapping>
</web-app>

spring-dao.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"
       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">

    <context:property-placeholder location="classpath:jdbc.properties"/>

    <!--数据库连接池-->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="${jdbc.driver}"/>
        <property name="jdbcUrl" value="${jdbc.url}"/>
        <property name="user" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>

        <!--c3p0设置-->
        <property name="checkoutTimeout" value="1000"/>
        <property name="acquireRetryAttempts" value="3"/>

    </bean>

    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!--注入数据库连接池-->
        <property name="dataSource" ref="dataSource"/>
        <!--注入全局配置-->
        <property name="configLocation" value="classpath:mybatis-config.xml"/>
        <!--别名包-->
        <property name="typeAliasesPackage" value="com.rz.entity"/>
        <!--mapper文件扫描-->
        <property name="mapperLocations" value="classpath:mapper/*.xml"/>
    </bean>

    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <!--新的,防止加载时jdbc.properties文件还没加载进来-->
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />

        <property name="basePackage" value="com.rz.dao"/>
    </bean>

    <bean id="redisDao" class="com.rz.dao.cache.RedisDao">
        <constructor-arg index="0" value="192.168.1.108"/>
        <constructor-arg index="1" value="6379"/>
    </bean>
</beans>

spring-service.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:tx="http://www.springframework.org/schema/tx"
       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/tx http://www.springframework.org/schema/tx/spring-tx.xsd">

    <!--扫描service包下注解-->
    <context:component-scan base-package="com.rz.service"/>

    <!--配置事物-->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>

    <!--开启注解式的事物-->
    <tx:annotation-driven transaction-manager="transactionManager"/>
</beans>

spring-web.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:mvc="http://www.springframework.org/schema/mvc"
       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/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:annotation-driven/>

    <!--资源路径配置-->
    <mvc:default-servlet-handler/>

    <!--配置viewresolver-->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
        <property name="prefix" value="/WEB-INF/view/"/>
        <property name="suffix" value=".jsp"/>
    </bean>

    <!--扫描控制器中注解-->
    <context:component-scan base-package="com.rz.controller"/>
</beans>

mybatis-config.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">
<configuration>
    <settings>
        <setting name="useGeneratedKeys" value="true"/>
        <!--默认开启别名转化-->
        <setting name="useColumnLabel" value="true"/>
        <setting name="mapUnderscoreToCamelCase" value="true"/>
    </settings>
</configuration>

logback.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="true">
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <!-- encoders are  by default assigned the type
             ch.qos.logback.classic.encoder.PatternLayoutEncoder -->
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>

    <root level="debug">
        <appender-ref ref="STDOUT" />
    </root>
</configuration>

jdbc.properties

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://192.168.1.108:3306/ssm
jdbc.username=root
jdbc.password=123456xxx

相关文章

  • 解决SSM+VUE对接跨域问题

    环境配置 基本框架搭建 可参考本人博客地址基本SSM框架搭建 SSM前后分离配置 解决SSM+VUE跨域问题 配置...

  • 分享一些ssm(springmvc+spring+mybatis

    1,ssm的mybatis的逆向生成代码的demo 2,ssm的多数据源配置demo 3,ssm的多视图解析配置的...

  • SpringMVC+Spring+mybatis+Redis项目

    一.SSM项目-分布式项目结构搭建二.SSM项目-Spring mybatis mysql配置实现三.SSM项目-...

  • JAVA 整合websocket

    SSM整合websocket 一、maven配置 二、ContextXML配置 contextXML添加约束 配置...

  • idea配置SSM

    SSM基本流程 tomcat配置 mysql配置 maven配置 intellij idea配置 一. 新建工程 ...

  • Maven分模块构建工程(构建SSM工程)

    将 SSM 工程拆分为多个模块开发: ssm_parent:将所需的依赖都配置在 pom 中。ssm_dao:负责...

  • day08

    SSM SSM 应用搭建 1. 部署 Spring + Spring MVC 导入包 配置Spring MVC的前...

  • SSM框架配置之web.xml 1.0

    SSM:SpringMVC+Spring+MyBatis 编写SSM整合的关键配置文件 web.xml,sprin...

  • SSM整合配置

    SSM 配置 配置文件 sqlMapConfig.xml applicationContext-dao.xml d...

  • SSM整合

    简单SSM项目pom文件 配置文件 配置web.xml 配置jdbc.properties 配置logback.x...

网友评论

      本文标题:ssm配置

      本文链接:https://www.haomeiwen.com/subject/kxkvyttx.html