首页 > 其他分享 >SSM框架配置

SSM框架配置

时间:2022-10-19 10:48:13浏览次数:49  
标签:xml 框架 spring 配置 springframework appender SSM org log4j

1. pom.xml

<dependencies>
<!--    junit 测试-->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>

<!--    spring 核心-->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>4.3.2.RELEASE</version>
    </dependency>
<!--    spring test-->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-test</artifactId>
      <version>4.3.2.RELEASE</version>
    </dependency>
<!--    spring jdbc-->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jdbc</artifactId>
      <version>4.3.2.RELEASE</version>
    </dependency>
<!--    spring 事务-->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-tx</artifactId>
      <version>4.3.2.RELEASE</version>
    </dependency>
    <!--      切面编程-->
    <dependency>
      <groupId>org.aspectj</groupId>
      <artifactId>aspectjweaver</artifactId>
      <version>1.8.9</version>
    </dependency>
      <dependency>
          <groupId>mysql</groupId>
          <artifactId>mysql-connector-java</artifactId>
          <version>8.0.26</version>
      </dependency>
    <dependency>
      <groupId>c3p0</groupId>
      <artifactId>c3p0</artifactId>
      <version>0.9.1.2</version>
    </dependency>
    <!--    mybatis-->
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis</artifactId>
      <version>3.4.5</version>
    </dependency>
    <!--    mybatis与spring整合-->
      <dependency>
          <groupId>org.mybatis</groupId>
          <artifactId>mybatis-spring</artifactId>
          <version>2.0.1</version>
      </dependency>

    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-log4j12</artifactId>
      <version>1.7.2</version>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>1.7.2</version>
    </dependency>

<!--      mybatis分页插件-->
      <dependency>
          <groupId>com.github.pagehelper</groupId>
          <artifactId>pagehelper</artifactId>
          <version>5.1.10</version>
      </dependency>
      <!--      spring web-->
      <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-web</artifactId>
          <version>4.3.2.RELEASE</version>
      </dependency>
      <!--      spring mvc-->
      <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-webmvc</artifactId>
          <version>4.3.2.RELEASE</version>
      </dependency>
      <!--          web servlet-->
      <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>javax.servlet-api</artifactId>
          <version>3.0.1</version>
      </dependency>
      <!--    json-->
      <dependency>
          <groupId>com.fasterxml.jackson.core</groupId>
          <artifactId>jackson-core</artifactId>
          <version>2.7.0</version>
      </dependency>
      <dependency>
          <groupId>com.fasterxml.jackson.core</groupId>
          <artifactId>jackson-databind</artifactId>
          <version>2.7.0</version>
      </dependency>
      <dependency>
          <groupId>com.fasterxml.jackson.core</groupId>
          <artifactId>jackson-annotations</artifactId>
          <version>2.7.0</version>
      </dependency>
      <!--文件上传-->
      <dependency>
          <groupId>commons-fileupload</groupId>
          <artifactId>commons-fileupload</artifactId>
          <version>1.3.2</version>
      </dependency>

  </dependencies>

<build>
    <finalName>ssm</finalName>
      <resources>
          <resource>
              <directory>src/main/resources</directory>
          </resource>
          <resource>
              <directory>src/main/java</directory>
              <includes>
                  <include>**/*.xml</include>
                  <include>**/*.properties</include>
                  <include>**/*.tld</include>
              </includes>
              <filtering>false</filtering>
          </resource>
      </resources>

    <pluginManagement>
      <plugins>
          <plugin>
              <groupId>org.mortbay.jetty</groupId>
              <artifactId>maven-jetty-plugin</artifactId>
              <version>6.1.25</version>
              <configuration>
                  <scanIntervalSeconds>10</scanIntervalSeconds>
                  <contextPath>/</contextPath>
              </configuration>
          </plugin>
      </plugins>
    </pluginManagement>
  </build>

2. 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_3_0.xsd"
         id="WebApp_ID" version="3.0">
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring.xml</param-value>
  </context-param>

  <listener>
    <listener-class>
      org.springframework.web.context.ContextLoaderListener
    </listener-class>
  </listener>

  <!-- 配置前端控制器 -->
  <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:mvc.xml</param-value>
    </init-param>
    <!--    启动容器初始化该Servlet-->
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>mvc</servlet-name>
    <!--    拦截请求-->
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>

  <!-- post请求 字符编码过滤器 -->
  <filter>
    <description>char encoding filter</description>
    <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>



</web-app>

resources文件夹下的配置文件

3. spring.xml

<context:component-scan base-package="org.example.ssm">
    <context:exclude-filter type="annotation"
                            expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<context:property-placeholder location="classpath:db.properties"/>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" >
    <property name="driverClass" value="${jdbc.driver}"></property>
    <property name="jdbcUrl" value="${jdbc.url}"></property>
    <property name="user" value="${jdbc.username}"></property>
    <property name="password" value="${jdbc.password}"></property>
</bean>
<bean id="txManager"
      class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource"></property>
</bean>
<tx:advice id="txAdvice" transaction-manager="txManager">
    <tx:attributes>
        <tx:method name="add*" propagation="REQUIRED"/>
        <tx:method name="insert*" propagation="REQUIRED"/>
        <tx:method name="update*" propagation="REQUIRED"/>
        <tx:method name="delete*" propagation="REQUIRED"/>
    </tx:attributes>
</tx:advice>
<!--    aop-->
<aop:aspectj-autoproxy />
<aop:config>
    <aop:pointcut id="servicePointcut"
                  expression="execution(* org.example.ssm.service..*.*(..))"/>
    <aop:advisor advice-ref="txAdvice" pointcut-ref="servicePointcut"></aop:advisor>
</aop:config>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource"></property>
    <property name="configLocation" value="classpath:mybatis.xml"></property>
    <property name="mapperLocations" value="classpath:org/example/ssm/mapper/*.xml"></property>
</bean>
<bean id="mapperScanner" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" value="org.example.ssm.dao"></property>
    <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
</bean>
```

4.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: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">

<!--    扫描com.springmvc.crm下包-->
    <context:component-scan base-package="org.example.ssm.controller"></context:component-scan>

    <!--    mvc 注解驱动 并添加json支持-->
    <mvc:annotation-driven>
        <mvc:message-converters>
<!--                返回信息为字符串时候的处理-->
            <bean class="org.springframework.http.converter.StringHttpMessageConverter"></bean>
<!--                将对象转化为json-->
            <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"></bean>
        </mvc:message-converters>
    </mvc:annotation-driven>

<!--    静态资源文件放行处理-->
    <mvc:default-servlet-handler/>
    <!--拦截器-->
    <!--
    <mvc:interceptors>
        <mvc:interceptor>
            <mvc:mapping path="/**"/>
            <mvc:exclude-mapping path="/user/login.do"/>
            <bean class="org.xxx.springmvc.interceptors.inter3"></bean>
        </mvc:interceptor>
    </mvc:interceptors>
    -->

    <!--    视图解析器-->
    <bean id="defaultViewResolver"
          class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property>
        <property name="contentType" value="text/html"></property>
        <property name="prefix" value="/WEB-INF/jsp/"></property>
        <property name="suffix" value=".jsp"></property>
    </bean>

    <!--    文件上传-->
    <bean id="multipartResolver"
          class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="maxUploadSize">
            <value>104857600</value>
        </property>
        <property name="maxInMemorySize">
            <value>4096</value>
        </property>
    </bean>

</beans>

5.mybatis.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>
    <typeAliases>
        <package name="org.example.ssm.vo"></package>
    </typeAliases>
    <plugins>
        <plugin interceptor="com.github.pagehelper.PageInterceptor"></plugin>
    </plugins>
</configuration>

6.db.properties

jdbc.driver =com.mysql.cj.jdbc.Driver
jdbc.url =jdbc:mysql://localhost:3306/ssm?characterEncoding=utf8&useUnicode=true&useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true
jdbc.username =root
jdbc.password =

7. log4j.properties

#????DEBUG????????console?file???????console?file?????????
log4j.rootLogger=DEBUG,console

#??????????
log4j.appender.console = org.apache.log4j.ConsoleAppender
#log4j.appender.console.Target = System.out
#log4j.appender.console.Threshold=DEBUG
log4j.appender.console.layout = org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d [%t] %p [%c] - <%m>%n

#?????????
#log4j.appender.file = org.apache.log4j.RollingFileAppender
#log4j.appender.file.File=./log/logFile.log
#log4j.appender.file.MaxFileSize=10mb
#log4j.appender.file.Threshold=DEBUG
#log4j.appender.file.layout=org.apache.log4j.PatternLayout
#log4j.appender.file.layout.ConversionPattern=[%p][%d{yy-MM-dd}][%c]%m%n

#??????
log4j.logger.java.sql.ResultSet=INFO
log4j.logger.org.apache=INFO
log4j.logger.java.sql.Connection=DEBUG
log4j.logger.java.sql.Statement=DEBUG
log4j.logger.java.sql.PreparedStatement=DEBUG

标签:xml,框架,spring,配置,springframework,appender,SSM,org,log4j
From: https://www.cnblogs.com/lwx11111/p/16805383.html

相关文章

  • 如何合理的配置HTTP代理进行大数据分析
    互联网营销战要抢占先机,数据是企业的核心资产。通过数据分析,我们可以从中探索出一条新的盈利道路,一条符合用户需求的道路。而在HTTP代理的介入之下,数据挖掘已经不再是......
  • Linux下编写ENC28J60网卡驱动,完善网络设备框架
    一、框架模型linux下设备驱动都有一套标准的结构,字符设备,块设备,网络设备都是自己的一套框架。编写驱动只需要把内核的框架搞清楚,然后照着结构填入参数,注册进内核,在应用层就......
  • Spring日志打印配置
    日志打印配置示例:<?xmlversion="1.0"encoding="UTF-8"?><!--Copyright2010-2011ThemyBatisTeamLicensedundertheApacheLicense,Version2.0(the"Lice......
  • [原创]一款基于Reactor线程模型的java网络爬虫框架
    AJSpridergithub:​​https://github.com/zhuchangwu/AJSpider​​概述AJSprider是笔者基于Reactor线程模式+Jsoup+HttpClient封装的一款轻量级java多线程网络爬虫框架,简......
  • 扔掉工具类!MyBatis 一个简单配置搞定加密、解密,不能太方便了~!
    来源:juejin.cn/post/6963811586184052767前言:介绍一个简单的MyBatis加解密方式,日常学习工作中提及这种方法的比较少,所以拿来说说,如果已经知道这种方法的忽略本文!一、背景......
  • 交换机的Telnet远程登陆配置
    一、实验目的交换机的Telnet远程登陆配置二、实验环境Windows10操作系统下的CirscoPacketTracer5.3三、实验原理与步骤1、设置交换机IP地址2、设置交换机权限密码3......
  • winfrom 中配置log4日志
    一、下载log4net组件直接引入log4net.dll文件到引用,或者使用NuGet,搜索log4net下载到项目中  二、创建配置一个log4net.config文件(将此文件属性设置为:始终复制),文件内......
  • Ubuntu安装并配置mysql
    Ubuntu安装并配置mysql安装sudoaptmysql-server-8.0修改root密码通过其他用户账号登陆MYSQL1.执行sudovim/etc/mysql/debian.cnf2.通过账号登陆mysql-ude......
  • Java云原生崛起微服务框架Quarkus入门实践
    @目录概述定义GraalVM简介为何使用特性官方性能实战入门示例步骤安装GraalVM创建quarkus工程Idea导入项目Idea运行和调试打包成普通的Jar打包成依赖GraalVM二进制文件打包......
  • jmeter环境配置
    命令行输入Jmeter提示不是内部或外部命令,需要在环境变量path中添加jmeter的bin目录绝对路径我的电脑》右击》属性》高级系统变量》环境变量》path》后面加上bi......