• ssm整合各配置文件


    ssm整合

    1、配置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"

                   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>ssm01</display-name>

      <!-- 配置springmvc -->

      <servlet>

        <servlet-name>springmvc</servlet-name>

        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

        <!-- 加载springmvc的配置文件 -->

        <init-param>

            <param-name>contextConfigLocation</param-name>

            <param-value>classpath:springmvc.xml</param-value>

        </init-param>

      </servlet>

       <servlet-mapping>

        <servlet-name>springmvc</servlet-name>

        <url-pattern>*.do</url-pattern>

      </servlet-mapping>

      <!-- post乱码配置 -->

      <filter>

        <filter-name>characterEncoding</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>characterEncoding</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:applicationContext.xml</param-value>

      </context-param>

      <welcome-file-list>

        <welcome-file>index.html</welcome-file>

        <welcome-file>index.htm</welcome-file>

        <welcome-file>index.jsp</welcome-file>

        <welcome-file>default.html</welcome-file>

        <welcome-file>default.htm</welcome-file>

        <welcome-file>default.jsp</welcome-file>

      </welcome-file-list>

    </web-app>

    2、配置springmvc配置文件springmvc.xml

    <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"

           xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"

           xsi:schemaLocation="http://www.springframework.org/schema/beans

                http://www.springframework.org/schema/beans/spring-beans-3.2.xsd

                http://www.springframework.org/schema/mvc

                http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd

                http://www.springframework.org/schema/context

                http://www.springframework.org/schema/context/spring-context-3.2.xsd

                http://www.springframework.org/schema/aop

                http://www.springframework.org/schema/aop/spring-aop-3.2.xsd

                http://www.springframework.org/schema/tx

                http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">

       

        <!-- 配置扫描 -->

        <context:component-scan base-package="com.jlm"></context:component-scan>

       

        <!-- 使用一句话配置处理器映射器、处理器适配器 -->

        <mvc:annotation-driven/>

        <!-- 配置springmvc的视图解析器 -->

        <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">

            <property name="prefix" value="/WEB-INF/pages/"></property>

            <property name="suffix" value=".jsp"></property>

        </bean>

           

    </beans>

    3、配置mybatis配置文件 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">

    <configuration>

    <!-- 加载映射文件 -->

    <!-- <mappers>

        <package name="com.jlm.dao"/>

    </mappers> -->

    </configuration>

    4、配置spring配置文件applicationContext.xml

    <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"

           xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"

           xsi:schemaLocation="http://www.springframework.org/schema/beans

                http://www.springframework.org/schema/beans/spring-beans-3.2.xsd

                http://www.springframework.org/schema/mvc

                http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd

                http://www.springframework.org/schema/context

                http://www.springframework.org/schema/context/spring-context-3.2.xsd

                http://www.springframework.org/schema/aop

                http://www.springframework.org/schema/aop/spring-aop-3.2.xsd

                http://www.springframework.org/schema/tx

                http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">

       

        <!-- 配置扫描包 -->

        <context:component-scan base-package="com.jlm"></context:component-scan>

       

        <!-- 加载配置文件 -->

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

       

        <!-- 第一步:配置数据源 -->

        <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">

            <property name="jdbcUrl" value="${jdbc.url}"></property>

            <property name="driverClass" value="${jdbc.driver}"></property>

            <property name="user" value="${jdbc.username}"></property>

            <property name="password" value="${jdbc.password}"></property>

        </bean>

       

        <!-- 第二步:配置sqlSessionFactory,生产session -->

        <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">

            <property name="dataSource" ref="dataSource"></property>

            <property name="configLocation" value="classpath:SqlMapConfig.xml"></property>

        </bean>

       

        <!-- 配置mybatis接口代理开发 -->

        <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">

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

            <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>

        </bean>

       

        <!-- 第三步:配置事务 -->

        <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

            <property name="dataSource" ref="dataSource"></property>

        </bean>

        <!-- 第四步:配置通知 -->

        <tx:advice id="txAdvice" transaction-manager="transactionManager">

            <tx:attributes>

                <tx:method name="save*" propagation="REQUIRED"/>

                <tx:method name="update*" propagation="REQUIRED"/>

                <tx:method name="delete*" propagation="REQUIRED"/>

                <tx:method name="insert*" propagation="REQUIRED"/>

                <tx:method name="*" propagation="REQUIRED"/>

            </tx:attributes>

        </tx:advice>

       

        <!-- 第五步:配置需要拦截的service -->

        <aop:config>

            <aop:advisor advice-ref="txAdvice" pointcut="execution(* com.jlm.service.*.*(..))"/>

        </aop:config>

           

    </beans>

    5、Log4j.properties

    ### direct log messages to stdout ###

    log4j.appender.stdout=org.apache.log4j.ConsoleAppender

    log4j.appender.stdout.Target=System.out

    log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

    log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

    ### direct messages to file mylog.log ###

    log4j.appender.file=org.apache.log4j.FileAppender

    log4j.appender.file.File=c:/mylog.log

    log4j.appender.file.layout=org.apache.log4j.PatternLayout

    log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

    ### set log levels - for more verbose logging change 'info' to 'debug' ###

    log4j.rootLogger=debug, stdout

    6、Jdbc.properties

    jdbc.url =jdbc:mysql:///mybatis

    jdbc.driver =com.mysql.jdbc.Driver

    jdbc.username=root

    jdbc.password=123456

  • 相关阅读:
    SQLSERVER 远程登录18456错误
    谁用掉了我的数据库空间?
    Zabbix-微信报警
    Mailx安装与使用
    Redis-集群操作
    Redis-集群部署
    十、Zabbix-自动关联模板
    九、Zabbix-触发器
    八、Zabbix-应用集、监控项
    七、Zabbix-模板,应用集,监控项,触发器
  • 原文地址:https://www.cnblogs.com/wldbk/p/10517333.html
Copyright © 2020-2023  润新知