总结文件配置

Posted 金石不渝

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了总结文件配置相关的知识,希望对你有一定的参考价值。

总体大概目录
主要 配置:pom.xml 配置、web.xml配置、applicationContext.xml配置、springmvc.xml配置
日志log4j2.xml、xxMapper.xml配置;
对三层的MVC搭建:entity层、service层、controller层;
对象和SQL映射mapper层;

第一部分:文件初始化,文件配置

1 对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>org.example</groupId>
  <artifactId>EpidemicBigData</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>EpidemicBigData 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.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
<!--    1、统一控制版本-->
    <spring-version>5.1.6.RELEASE</spring-version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
<!--    2、导入spring包-->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>$spring-version</version>
    </dependency>
<!--    3、导入切面通知包-->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-aspects</artifactId>
      <version>$spring-version</version>
    </dependency>
<!--    4、导入orm 和aspects一起的-->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-orm</artifactId>
      <version>$spring-version</version>
    </dependency>
<!--    5、导入mybatis于spring 连接包-->
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis-spring</artifactId>
      <version>2.0.5</version>
    </dependency>
<!--    6、导入mybatis包-->
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis</artifactId>
      <version>3.5.5</version>
    </dependency>
<!--    7、导入数据库连接包-->
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>8.0.20</version>
    </dependency>
<!--    8、导入hikaricip包,数据连接池-->
    <dependency>
      <groupId>com.zaxxer</groupId>
      <artifactId>HikariCP</artifactId>
      <version>3.4.5</version>
    </dependency>
<!--    9、springmvc 包-->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>$spring-version</version>
    </dependency>
<!--    10、构造器,geter 和setter -->
    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
      <version>1.18.12</version>
    </dependency>
<!--    11、json格式配置-->
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <version>2.11.2</version>
    </dependency>
<!--    12、日志配置-->
    <!--log4j日志-->
    <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j-impl -->
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-slf4j-impl</artifactId>
      <version>2.11.2</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-web -->
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-web</artifactId>
      <version>2.11.2</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-jcl -->
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-jcl</artifactId>
      <version>2.11.2</version>
    </dependency>






  </dependencies>

  <build>
    <finalName>EpidemicBigData</finalName>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-war-plugin</artifactId>
          <version>3.2.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

3、对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">
  <!-- 将前端配置文件注入  -->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:META-INF/applicationContext.xml</param-value>
  </context-param>
<!-- 配置核心组件:前端控制器-->
  <servlet>
    <servlet-name>mvc</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <!--    初始化参数 servlet的声明周期  -->
    <init-param>
      <!--      配置springmvc的核心配置文件-->
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:META-INF/springmvc.xml</param-value>
    </init-param>
    <!--    配置服务器在启动的时候加载 <servlet>   -->
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>mvc</servlet-name>
    <!--      所有的servlet都生效-->
    <url-pattern>/</url-pattern>
  </servlet-mapping>

  <!--    过滤器配置-->
  <filter>
    <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>

  <listener>
    <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
  </listener>

  <listener>
    <listener-class>org.apache.logging.log4j.web.Log4jServletContextListener</listener-class>
  </listener>
<!--  将log4j2.xml导入 -->
  <context-param>
  <param-name>log4jConfiguration</param-name>
  <!--默认是classpath下的log4j2.xml-->
  <param-value>classpath:log4j2.xml</param-value>
</context-param>
</web-app>

4、对applicationContext.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: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-4.3.xsd
                           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
                           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
                           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">

   <!--   1、 开启包扫描 主要是扫描mapper  service  可以配置将controller排除掉-->
   <context:component-scan base-package="org.lsj">
      <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
      <context:exclude-filter type="annotation" expression="org.springframework.web.bind.annotation.RestController"/>
   </context:component-scan>

   <!--2、写数据源配置-->
   <bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource">
      <property name="driverClassName" value="com.mysql.cj.jdbc.Driver"></property>
      <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/patient?serverTimezone=Asia/Shanghai&amp;useUnicode=true&amp;characterEncoding=utf8"></property>
      <property name="username" value="root"></property>
      <property name="password" value="123456"></property>
      <!--        数据库连接池中最大连接数量-->
      <property name="maximumPoolSize" value="20"></property>
      <!--        配置测试连接是否可用的查询语句-->
      <property name="connectionTestQuery" value="select 1"></property>
   </bean>
   <!--    3、配置 SqlSessionFactory  mybatis-spring-->
   <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
      <!--        (1)、提供数据源-->
      <property name="dataSource" ref="dataSource"></property>
      <!--        (2)、mapper 的位置  相当于mybatis框架的mapper注册-->
      <property name="mapperLocations" value="classpath:org/lsj/**/*.xml"></property>
   </bean>
   <!--    4、mapper接口的扫描器,目的是将mybatis接口的实现类纳入spring容器-->
   <bean id="mapperScanner" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
      <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
      <!--        (2)、要扫描的基础包:在基础包下进行递归扫描,找接口[会把service接口一并扫描]-->
      <property name="basePackage" value="org.lsj"></property>
      <!--        (3)、只扫描带有@mapper 的接口,过滤掉service接口-->
      <property name="annotationClass" value="org.apache.ibatis.an

以上是关于总结文件配置的主要内容,如果未能解决你的问题,请参考以下文章

患者的0RR是啥?

美联储“盯上”数字货币,大机会来了?

求这个c语言题目的解题思路和解法?

python疫情数据分析怎么和excel连接

新冠肺炎感染人数为何远超SARS?

数据分析:PYTHON可以预测新冠病毒得病人数吗?