开源项目教程:Clean Architecture Example Java Spring Boot
1. 项目的目录结构及介绍
项目的目录结构如下:
clean-architecture-example-java-spring-boot
├── src
│ ├── main
│ │ ├── java
│ │ │ ├── com
│ │ │ │ ├── example
│ │ │ │ │ ├── application
│ │ │ │ │ │ ├── ports
│ │ │ │ │ │ │ ├── incoming
│ │ │ │ │ │ │ │ ├── use_cases
│ │ │ │ │ │ │ │ │ ├── add_customer
│ │ │ │ │ │ │ │ │ ├── get_customer
│ │ │ │ │ │ │ │ │ ├── remove_customer
│ │ │ │ │ │ │ │ │ └── update_customer
│ │ │ │ │ │ │ └── outgoing
│ │ │ │ │ │ │ └── customer_repository
│ │ │ │ │ │ └── services
│ │ │ │ │ ├── domain
│ │ │ │ │ │ └── entities
│ │ │ │ │ ├── infrastructure
│ │ │ │ │ │ ├── config
│ │ │ │ │ │ ├── controllers
│ │ │ │ │ │ ├── persistence
│ │ │ │ │ │ │ ├── h2
│ │ │ │ │ │ │ ├── jpa
│ │ │ │ │ │ │ └── mappers
│ │ │ │ │ │ └── security
│ │ │ │ │ └── web
│ │ │ └── resources
│ │ │ ├── application.properties
│ │ │ └── schema.sql
│ └── test
│ └── java
│ └── com
│ └── example
│ └── application
│ └── services
└── pom.xml
目录结构介绍
src/main/java/com/example/application
: 包含应用的核心逻辑,包括用例、服务和端口。src/main/java/com/example/domain
: 包含领域模型和实体。src/main/java/com/example/infrastructure
: 包含基础设施代码,如配置、控制器、持久化和安全相关代码。src/main/resources
: 包含应用的配置文件和数据库初始化脚本。src/test/java
: 包含测试代码。pom.xml
: Maven项目配置文件。
2. 项目的启动文件介绍
项目的启动文件是 src/main/java/com/example/web/CleanArchitectureExampleApplication.java
。这个文件是Spring Boot应用的入口点,负责启动整个应用。
package com.example.web;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class CleanArchitectureExampleApplication {
public static void main(String[] args) {
SpringApplication.run(CleanArchitectureExampleApplication.class, args);
}
}
3. 项目的配置文件介绍
项目的配置文件是 src/main/resources/application.properties
。这个文件包含了应用的各种配置,如数据库连接、服务器端口等。
# 服务器端口
server.port=8080
# 数据库配置
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=password
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
# H2控制台配置
spring.h2.console.enabled=true
spring.h2.console.path=/h2-console
# 日志配置
logging.level.org.springframework=INFO
logging.level.com.example=DEBUG
以上是关于 `Clean Architecture Example Java Spring