码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2020-01-14 16:33:53      阅读:110      评论:0      收藏:0      [点我收藏+]

标签:index   rect   sources   实体   macos   aging   pid   ram   entity   

  • 环境: MacOS + IntelliJ IDEA 2019.3.1 (Ultimate Edition)

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、创建存放源码文件的文件夹

  • 选择cats->右键->New->Directory->src/main/java
  • 选择java文件夹->右键->Mark Directory as->Sources Root

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

  • 选择cats->右键->New->Directory->src/main/resources
  • 选择resources文件夹->右键->Mark Directory as->Resources Root

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

  • 选择cats->右键->New->Directory->src/main/webapp

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

  • 选择webapp->右键->New->Directory->WEB-INF

7、在WEB-INF目录下创建web.xml

  • 选择WEB-INF->右键->New->file->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、构建单元测试目录

  • 选择cats->右键->New->Directory->src/test/java
  • 选择java文件夹->右键->Mark Directory as->Test Sources Root

9、创建Package

  • 选择main/java->右键->New->Package->com.coding.cats

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

  • 选择com.coding.cats -> New->Package->com.coding.cats.dao

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

  • 选择com.coding.cats -> New->Package->com.coding.cats.service

12、创建视图层web文件夹

  • 选择com.coding.cats -> New->Package->com.coding.cats.web

13、创建实体类entity文件夹

  • 选择com.coding.cats -> New->Package->com.coding.cats.entity

14、创建spring-context.xml

  • 选择resource->右键->New->file->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

  • 选择resource->右键->New->file->log4j.properties
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

  • 选择webapp->右键->New->file->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 管理项目

  • 选择pom.xml->右键->Add as Maven Project

18、运行Spring项目
技术图片

至此,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实战 - 手动创建Spring项目结构

标签:index   rect   sources   实体   macos   aging   pid   ram   entity   

原文地址:https://www.cnblogs.com/9coding/p/12192438.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!