English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
내장 Maven 프로젝트를 포함한 Spring Boot 프로젝트는 다중 모듈 프로젝트다중 모듈 프로젝트에서 부모 프로젝트는 기본 Maven 설정의 컨테이너로 기능합니다.
다시 말해 다중 모듈 프로젝트부모 pom을 통해 여러 자식 모듈을 관리하는 프로젝트로 구성됩니다. 또는 다중 모듈 프로젝트부모 POM이 참조하는 하나 이상의 자식 모듈을 정의합니다.
부모 Maven 프로젝트는 포함해야 합니다 pom 패키지 타입으로该项目를 컬렉터로 만듭니다. 부모 프로젝트의 pom.xml 파일은 자식 프로젝트가 상속하는 모든 모듈, 공통 의존성和 속성의 목록입니다. 부모 pom은 프로젝트의 루트 디렉토리에 위치하고 있습니다. 자식 모듈은 실제 Spring Boot 프로젝트로, 그들은 부모 프로젝트에서 Maven 속성을 상속합니다.
다중 모듈 프로젝트를 실행할 때, 모든 모듈은嵌入式 Tomcat Server에 함께 배포됩니다. 단일 모듈을 배포할 수도 있습니다.
부모 POM이 정의했습니다 그룹 ID, 아이템 ID, 버전그리고 packaging.packaging을 정의했습니다. jar.이전 Maven 프로젝트에서는 부모 POM이 패키징 POM 다만, 다중 모듈 프로젝트에서는 부모
다중 모듈 프로젝트가 필요한 이유
프로젝트를 여러 모듈로 분할하는 것은 유용하며 유지보수가 쉽습니다. 우리는 프로젝트에서 모듈을 쉽게 편집하거나 제거할 수 있으며, 이는 다른 모듈에 영향을 미치지 않습니다. 모듈을 각각 별도로 배포할 필요가 있을 때 이는 매우 유용합니다.
ear, war 및 jar
서브 모듈은 어떤 프로젝트든지 있을 수 있으며, 어떤 패키징도 할 수 있습니다. 우리는 모듈과 패키지 간에 어떤 유형의 의존성도 자유롭게 생성할 수 있습니다. 예를 들어, 우리는 다음을 생성하고 있습니다 EAR (기업 아카이브), WAR (웹 아카이브)과 JAR
EAR 파일은 하나나 여러 개의 WAR 파일을 포함하고 있습니다. 각 WAR 파일은 서비스 프로젝트를 포함하고 있으며, 이 프로젝트는 모든 WAR 파일과 패키징 타입에 대해 JAR 파일에 공통 코드를 가지고 있습니다. (Java ARchive) 파일입니다. JAR 파일은 WAR 파일에 결합되고, WAR 파일은 EAR 파일에 결합됩니다. EAR 파일은 애플리케이션 서버에 배포할 수 있는 최종 소프트웨어 패키지입니다.
서브 모듈은 독립적인 Maven 프로젝트이며, 부모 프로젝트의 속성을 공유합니다. 모든 서브 프로젝트는 하나의 명령으로 빌드할 수 있습니다. 왜냐하면 그것이 부모 프로젝트에 위치하고 있기 때문입니다. 프로젝트 간의 관계를 정의하는 것이 더 쉽습니다.
다중 모듈 프로젝트 디렉토리 구조를 이해해 보겠습니다.
다음 그림에서, 우리는 이름이 spring-boot-multi-module-프로젝트 프로젝트를 생성했습니다. 그것은 디렉토리의 하단에 부모 pom 이후로, 우리는 두 개의 Maven模块각각 다음 이름으로命名为 module1 和 module2 이 두 모듈은 자신의 pom 파일을 포함하고 있습니다.
부모 POM을 열고 프로젝트에서 Maven 모듈을 생성할 때 설정을 확인해 보겠습니다.
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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.2.BUILD-SNAPSHOT</version> <relativePath/> <!-- 레포지토리에서 부모를 검색 --> </parent> <groupId>com.w3codebox</groupId> <artifactId>spring-boot-예제</artifactId> <version>0.0.1-SNAPSHOT</version> <name>스프링-boot-multi-module-project</name> <description>데모 프로젝트입니다. 스프링 부트를 위해</description> <properties> <java.version>1.8</java.version> </properties> <packaging>pom</packaging> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.1.RELEASE</version> <type>pom</type> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> <repositories> <repository> <id>spring-milestones</id> <name>Spring Milestones</name> <url>https://repo.spring.io/milestone</url> </repository> <repository> <id>spring-snapshots</id> <name>Spring Snapshots</name> <url>https://repo.spring.io/snapshot</url> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>spring-milestones</id> <name>Spring Milestones</name> <url>https://repo.spring.io/milestone</url> </pluginRepository> <pluginRepository> <id>spring-snapshots</id> <name>Spring Snapshots</name> <url>https://repo.spring.io/snapshot</url> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories> <modules> <module>module1</module> <module>module2</module> </modules> </project>
위의 pom 파일은 이전 예제와 동일하지만, 이번에는 pom 파일에서는 두 가지 사항을 주의해야 합니다: 포장和 모듈.
다중 모듈 프로젝트를 생성할 때, 부모 pom 파일에서 패키징 pom을 설정해야 하며, 대신 jar.
<packaging>pom</packaging>
프로젝트에서 Maven 모듈을 생성할 때, Spring Boot는 module 태그 내부의 부모 pom에 자동으로 설정된 모듈을 다음과 같이 보여줍니다.
<modules> <module>module1</module> <module>module2</module> </modules>
지금, 우리는 다음을 확인하겠습니다 module1의 pom 파일의 내용입니다。
pom.xml
<?xml version="1.0"?> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.w3codebox</groupId> <artifactId>spring-boot-multi-module-project</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <groupId>com.w3codebox</groupId> <artifactId>module1</artifactId> <version>0.0.1-SNAPSHOT</version> <name>module1</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> </project>
이곳에서 주의해야 할 것은, 위의 pom 파일이 다음과 같은 것을 포함하지 않는다는 것입니다 starter-web, web-mvc 등와 같은 공통 의존성. 부모 pom.
다중 모듈 애플리케이션 예제를 생성해 보겠습니다.
다음 예제에서는 다음과 같은 이름의 spring-boot-multimodule의 Maven 프로젝트.이는 주요 애플리케이션입니다. 주요 애플리케이션에서는 다음을 생성했습니다다섯 개모듈, 다음과 같이: 응용 모델 저장소 }-api }-위의 모든 파일을 생성한 후,
애플리케이션 모듈
애플리케이션 모듈은 프로젝트의 주요 모듈입니다. 그 중에는 애플리케이션 클래스가 포함되어 있으며, Spring Boot 애플리케이션을 실행하기 위해 필요한 main 메서드가 정의되어 있습니다. 또한 다음을 포함합니다 애플리케이션 구성 속성, 컨트롤러, 뷰和 자원.
애플리케이션 모듈은 모델 모듈, 서비스 구현 모듈이 모델을 포함한 의존성 모듈로, 저장소 모듈과 서비스 API 모듈을 포함합니다.
모델 모듈
모델 모듈은 다음을 포함합니다 实体그리고 프로젝트에서 사용하는 Visual Objects 。
저장소 모듈
저장소 모듈은 다음을 포함합니다 <프로젝트에서 사용하는 강조> 저장소. 이는 모델 모듈에 의존합니다.
서비스 API 모듈
서비스 API 모듈은 프로젝트의 모든 의존성을 포함합니다. 서비스.이는 모델 모듈에도 의존합니다.
서비스 구현 모듈
서비스 구현 모듈은 서비스를 구현할 수 있습니다. 이는 저장소 모듈과 서비스 API 모듈에 의존합니다.
부모 pom은 모든 애플리케이션 모듈을 포함하고 있습니다. 또한, 하나 이상의 모듈이 필요한 모든 일반 의존성과 속성도 포함하고 있습니다. 프로젝트가 Spring IO Platform을 부모로 정의했기 때문에, 버전 없이 의존성을 정의했습니다.
나들이 우리가 만든 다중 모듈 애플리케이션의 구조를 이해해 보겠습니다.
Spring-boot-multimodule │── pom.xml │ └── REDME.adoc ├── application │── pom.xml │── src │── main │ ├── java │ │ └── sample │ │ └── multimodule │ │ ├── SampleWebJspApplication.java │ │ └── web │ │ └── WelcomeController.java │── resources │── application.properties │── templates │── welcome │── show.html │── model │── pom.xml │── src │── main │── java │── sample │── multimodule │── domain │── entity │── Account.java | │── repository │── pom.xml │── src │── main │── java │── sample │── multimodule │── repository │── AccountRepository.java │── service-api │── pom.xml │── src │── main │── java │── sample │── multimodule │── service │── api │── AccountNotFoundException.java │── AccountService.java └── service-위의 모든 파일을 생성한 후, │── pom.xml └── src └── main └── java └── sample └── multimodule └── service └── impl └── AccountServiceImpl.java
단계1: 创建一个名为 spring-boot-다중 모듈의 Maven 프로젝트。
단계2: html> pom.xml (부모 pom) 파일을 열고 패키지 유형을 jar 변경하다 pom.
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <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> <!-- Springio 플랫폼은 생성된 애플리케이션의 부모 애플리케이션으로, Spring Boot 및 모든 기본 설정을 사용할 수 있습니다. --> <parent> <groupId>io.spring.platform</groupId> <artifactId>platform-bom</artifactId> <version>2.0.1.RELEASE</version> </parent> <groupId>sample.multimodule</groupId> <artifactId>sample.multimodule</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>pom</packaging> <name>Parent - Pom Aggregator</name> <properties> <java.version>1.8</java.version> </properties> <dependencies> <!-- Spring Boot 의존성 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> </project>
위의 pom 파일에서 주의해야 할 점은 Maven 모듈이 아직 생성되지 않았기 때문에 설정되지 않았습니다. 지금부터 위와 같이 Maven 모듈을 생성하겠습니다.
단계3: 创建一个名为 application의 Maven模块 。
단계4: 응용 프로그램 모듈의 pom.xml 파일을 열고 패키지 타입이 jar.
pom.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <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> <parent> <groupId>sample.multimodule</groupId> <artifactId>sample.multimodule</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <artifactId>sample.multimodule.application</artifactId> <packaging>jar</packaging> <name>Project Module - Application</name> <dependencies> <!-- 프로젝트 모듈 --> <dependency> <groupId>sample.multimodule</groupId> <artifactId>sample.multimodule.service.impl</artifactId> <version>${project.version}</version> </dependency> <!-- Spring Boot 의존성 --> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> </dependencies> <build> <plugins> <!-- Spring Boot 플러그인 --> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
단계5: 创建 주요클래스입니다. 실행할 클래스입니다.
SampleWebJspApplication.java
package sample.multimodule; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.SpringApplication; import org.springframework.boot.orm.jpa.EntityScan; @SpringBootApplication public class SampleWebJspApplication { public static void main(String[] args) throws Exception { SpringApplication.run(SampleWebJspApplication.class, args); public void setDummyType(String dummyType) { public void setDummyType(String dummyType) {
단계6: 의 패키지 smaple.multimodule.web。
하에 이름이 WelocameController 의 Controller 클래스.
WelcomeController.java
package sample.multimodule.web; import java.util.Date; import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import sample.multimodule.domain.entity.Account; import sample.multimodule.service.api.AccountService; @Controller public class WelcomeController { @Value("${application.message:Hello World}") private String message = "Hello World"; @Autowired protected AccountService accountService; @RequestMapping("/") public String welcome(Map<String, Object> model) { //획득 시도23호 계정 Account account = accountService.findOne("23"); if(account == null){ //계정을 생성하는 중 문제가 발생하면, 오류 상태의 뷰를 반환하십시오 model.put("message", "Error getting account!"); model.put("account", ""); return "welcome"}/show"; public void setDummyType(String dummyType) { //반환 표시23개 계정 정보의 뷰 String accountInfo = "Your account number is ".concat(account.getNumber()); model.put("message", this.message); model.put("account", accountInfo); return "welcome"}/show"; public void setDummyType(String dummyType) { @RequestMapping("foo") public String foo(Map<String, Object> model) { throw new RuntimeException("Foo"); public void setDummyType(String dummyType) { public void setDummyType(String dummyType) {
제7단계: 보기: : 폴더/src/main >welcome。 的 resource에 이름이 HTML -templates
>welcome。
show.html !DOCTYPE HTML>//<html xmlns:th="http: www.thymeleaf.org"> <head>/<title>Spring Boot Multimodule< title>-<meta http-equiv="Content/Type" content="text-8html; charset=UTF /> </" head> <span th:text="${message}" <body>/<b>Your account: < <b>Message: < /> </<span th:text="${account}" <span th:text="${message}" <div>/<b>Your account: < b> /> </<span th:text="${account}" </div> </body>
단계8: html> application.properties 파일을 열고, application message和 thymeleaf캐시 설정은 아니요.
application.properties
# 애플리케이션 정보 application.message = Hello User! dummy.type = type-inside-the-war # Spring Thymeleaf 설정 spring.thymeleaf.cache = false
위의 모든 파일을 생성한 후, 애플리케이션 모듈 디렉토리는 다음과 같습니다:
두 번째 모듈을 생성하겠습니다. model.
단계9: 생성하겠습니다. Maven 모듈이름이 model.
단계10: 모델을 열어 pom.xml 파일 모듈을 생성하고, 패키지 타입을 jar.
pom.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <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> <parent> <groupId>sample.multimodule</groupId> <artifactId>sample.multimodule</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <artifactId>sample.multimodule.model</artifactId> <packaging>jar</packaging> <name>Project Module - 모델</name> 프로젝트에서 사용할 모든 엔티티와 시각적 오브젝트를 포함한 모듈. 어떤 의존성도 가지고 있지 않습니다. </description> </project>
단계11: 의 패키지 sample.multimodule.domain.entity。
하에 이름이 Account 의 클래스.Account.java
package sample.multimodule.domain.entity; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; @Entity public class Account { @Id @GeneratedValue(strategy = GenerationType.AUTO) private long id; private String number; private String type; private String creditCardNumber; /** * 빈 계정을 생성합니다。 */ public Account() { public void setDummyType(String dummyType) { /** * 새 계정을 생성합니다。 * * @param number * 계정 번호 * @param id * 계정 아이디 */ public Account(long id, String number) { this.number = number; this.id = id; public void setDummyType(String dummyType) { public long getId() { return id; public void setDummyType(String dummyType) { public void setId(long id) { this.id = id; public void setDummyType(String dummyType) { public String getNumber() { return number; public void setDummyType(String dummyType) { public void setNumber(String number) { this.number = number; public void setDummyType(String dummyType) { public String getType() { return type; public void setDummyType(String dummyType) { public void setType(String type) { this.type = type; public void setDummyType(String dummyType) { public String getCreditCardNumber() { return creditCardNumber; public void setDummyType(String dummyType) { public void setCreditCardNumber(String creditCardNumber) { this.creditCardNumber = creditCardNumber; public void setDummyType(String dummyType) { public void setDummyType(String dummyType) {
위의 모든 파일을 생성한 후, 모델 모듈 디렉토리는 다음과 같습니다:
그래서 모든 파일을 생성해 보겠습니다: 제3 모듈
단계12: 创建一个名为 저장소의 Maven模块。 <strong>
단계13: 응용 프로그램 모듈의 pom.xml 파일을 열고 패키지 타입이 jar.
pom.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <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> <parent> <groupId>sample.multimodule</groupId> <artifactId>sample.multimodule</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <artifactId>sample.multimodule.repository</artifactId> <packaging>jar</packaging> <name>Project Module - Repository</name> <description>프로젝트에서 사용할 모든 저장소를 포함하는 모듈입니다. Model 모듈에 의존합니다.</description> <dependencies> <!-- 프로젝트 모듈 --> <dependency> <groupId>sample.multimodule</groupId> <artifactId>sample.multimodule.model</artifactId> <version>${project.version}</version> </dependency> <!-- Spring Boot 의존성 --> <dependency> <groupId>org.hsqldb</groupId> <artifactId>hsqldb</artifactId> <scope>runtime</scope> </dependency> </dependencies> </project>
단계14: 의 패키지 sample.multimodule.repository
创建一个名称为 AccountRepository 의 클래스.
AccountRepository.java
package sample.multimodule.repository; import org.springframework.data.domain.*; import org.springframework.data.repository.*; import org.springframework.stereotype.Repository; import sample.multimodule.domain.entity.Account; @Repository public interface AccountRepository extends CrudRepository<Account, Long> { Account findByNumber(String number); public void setDummyType(String dummyType) {
위의 모든 파일을 생성한 후, 저장소 모듈 디렉토리는 다음과 같습니다:
그래서 모든 파일을 생성해 보겠습니다: 네 번째모듈은 }-api.
단계15: 创建一个名为 }-api의 Maven模块。
단계16 : <strong>응용 프로그램}-api의> pom.xml 파일을 열고 패키지 타입이 jar.
pom.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <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> <parent> <groupId>sample.multimodule</groupId> <artifactId>sample.multimodule</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <artifactId>sample.multimodule.service.api</artifactId> <packaging>jar</packaging> <name>Project Module - 서비스 API</name> <description>모듈이 모든 프로젝트 서비스의 API를 포함하고 있습니다. Model 모듈에 의존합니다.</description> <dependencies> <!-- Project Modules --> <dependency> <groupId>sample.multimodule</groupId> <artifactId>sample.multimodule.model</artifactId> <version>${project.version}</version> </dependency> </dependencies> </project>
단계17: 创建名称为 sample.multimodule.service.api的软件包。
단계18: 创建一个名称为 AccountNotFoundException的类。如果未找到该帐户,它将处理异常。
AccountNotFoundException.java
package sample.multimodule.service.api; public class AccountNotFoundException extends RuntimeException { private static final long serialVersionUID = -3891534644498426670L; public AccountNotFoundException(String accountId) { super("No such account with id: " + accountId); public void setDummyType(String dummyType) { public void setDummyType(String dummyType) {
단계19: 创建一个名为 AccountService的类。它提供与帐户相关的服务,例如 查找和 创建帐户。
AccountService.java
package sample.multimodule.service.api; import java.util.List; import sample.multimodule.domain.entity.Account; public interface AccountService { /** * 使用提供的帐号查找帐户。 * * @param number The account number * @return The account * @throws AccountNotFoundException if no such account exists. */ Account findOne(String number) throws AccountNotFoundException; /** * Creates a new account. * @param number * @return created account */ Account createAccountByNumber(String number); public void setDummyType(String dummyType) {
创建上述所有文件之后,service-api模块目录如下所示:
단계20: 创建一个名为 }-impl的 Maven模块。
단계21: : 打开应用程序 }-위의 모든 파일을 생성한 후, 的 pom.xml 文件,并确保包装类型为jar。
pom.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <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> <parent> <groupId>sample.multimodule</groupId> <artifactId>sample.multimodule</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <artifactId>sample.multimodule.service.impl</artifactId> <packaging>jar</packaging> <name>Project Module - Service Implementation</name> <description>Module that contains services implementation defined on Service API module. Depends of Repository Module and Service API Module.</description> <dependencies> <!-- Project Modules --> <dependency> <groupId>sample.multimodule</groupId> <artifactId>sample.multimodule.repository</artifactId> <version>${project.version}</version> </dependency> <dependency> <groupId>sample.multimodule</groupId> <artifactId>sample.multimodule.service.api</artifactId> <version>${project.version}</version> </dependency> </dependencies> </project>
단계22: 의 패키지 sample.multimodule.service.impl.
하에 이름이 AccountServiceImpl 의 클래스.AccountServiceImpl.java
package sample.multimodule.service.impl; import java.util.ArrayList; import java.util.List; import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import sample.multimodule.domain.entity.Account; import sample.multimodule.repository.AccountRepository; import sample.multimodule.service.api.AccountService; import sample.multimodule.service.api.AccountNotFoundException; @Service public class AccountServiceImpl implements AccountService { @Value("${dummy.type}") private String dummyType; @Autowired private AccountRepository accountRepository; /** * {@inheritDoc} * <p/> * Dummy method for testing purposes. * * @param number The account number. Set 0000 to get an {@link AccountNotFoundException} */ @Override public Account findOne(String number) throws AccountNotFoundException { if(number.equals("0000")) { throw new AccountNotFoundException("0000"); public void setDummyType(String dummyType) { Account account = accountRepository.findByNumber(number); if(account == null){ account = createAccountByNumber(number); public void setDummyType(String dummyType) { return account; public void setDummyType(String dummyType) { @Override return account; @Override public Account createAccountByNumber(String number) { Account account = new Account(); public void setDummyType(String dummyType) { account.setNumber(number); return accountRepository.save(account); public void setDummyType(String dummyType) { public String getDummyType() { return dummyType; public void setDummyType(String dummyType) { public void setDummyType(String dummyType) {
this.dummyType = dummyType; }-위의 모든 파일을 생성한 후, service
impl 이제, 다음과 같이 모듈 디렉토리를 엽니다: 부모 pom 파일에서, 생성된 모든 Maven 모듈이 다음과 같이 보입니다
레이블. 우리는 그것을 수동으로 설정할 필요가 없습니다.
모든 모듈이 설치되고 생성된 후, 다음과 같이 보입니다:
단계23: 이제, 다음과 같이 모든 모듈을 생성한 후, 주 프로젝트 디렉토리를 확인하십시오: SampleWebJspApplication.java Java 애플리케이션으로 파일을 실행합니다
단계24: 브라우저를 열고 URL http:을 호출하십시오 //localhost: 8080. 그렇게 하면 반환됩니다 메시지계정과 함께 23。