其他分享
首页 > 其他分享> > Spring实战 - 手动创建Spring项目结构

Spring实战 - 手动创建Spring项目结构

作者:互联网

1、创建存放项目的文件夹
2、创建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.coding</groupId>
  <artifactId>cats</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>
  <dependencies>
    <!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>5.2.2.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>4.0.1</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/junit/junit -->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.13</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>log4j-over-slf4j</artifactId>
      <version>2.0.0-alpha1</version>
    </dependency>
  </dependencies>
</project>

3、创建存放源码文件的文件夹

4、创建存放资源文件的文件夹

5、创建存放配置文件的文件夹

6、在webapp 目录下创建WEB-INF

7、在WEB-INF目录下创建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">
</web-app>

8、构建单元测试目录

9、创建Package

10、创建数据访问层dao文件夹

11、创建业务逻辑层service 文件夹

12、创建视图层web文件夹

13、创建实体类entity文件夹

14、创建spring-context.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:aop="http://www.springframework.org/schema/aop"
  xmlns:tx="http://www.springframework.org/schema/tx"
  xmlns:context="http://www.springframework.org/schema/context"
  xsi:schemaLocation="
   http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
   http://www.springframework.org/schema/aop
   http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
   http://www.springframework.org/schema/tx
   http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
   http://www.springframework.org/schema/context
   http://www.springframework.org/schema/context/spring-context-3.0.xsd">
</beans>

15、创建了log4j.xml

log4j.rootLogger=INFO, console, file
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d %p [%c] - %m%n
log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
log4j.appender.file.File=logs/log.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.A3.MaxFileSize=1024KB
log4j.appender.A3.MaxBackupIndex=10
log4j.appender.file.layout.ConversionPattern=%d %p [%c] - %m%n

16、创建index.jsp

<%--
  Created by IntelliJ IDEA.
  User: 码出高薪
  Date: 2020/1/9
  Time: 10:17
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>码出高薪</title>
</head>
<body>
码出高薪
</body>
</html>

17、使用Maven 管理项目

18、运行Spring项目
码出高薪.png

至此,SPRING 项目结构构建完成!

├── cats
├── lib
└── src
    ├── main
    │   ├── java
    │   │   └── com
    │   │       └── coding
    │   │           └── cats
    │   │               ├── dao
    │   │               ├── service
    │   │               └── web
    │   ├── resources
    │   │   └── spring-context.xml
    │   └── webapp
    │       └── WEB-INF
    │           └── web.xml
    └── test
        └── java
    ├── pom.xml

标签:实战,Spring,手动,coding,cats,右键,New,com,log4j
来源: https://www.cnblogs.com/9coding/p/12192438.html