Java Spring Boot Gradle多模块项目控制器映射
我面临这样的问题:我想在我的项目中使用以下架构:Java Spring Boot Gradle多模块项目控制器映射,java,spring,spring-boot,gradle,architecture,Java,Spring,Spring Boot,Gradle,Architecture,我面临这样的问题:我想在我的项目中使用以下架构: -root |-核心 |-项目2 |-项目3 所以我有3个独立的模块。我希望模块proj2和proj3是一种具有唯一控制器的外观,但是它们都应该继承自核心项目,服务和DAO将位于该项目,以便我可以@Autowire它们。现在,当我将包含@SpringBootApplication的Application.java放入核心模块时,Spring不会扫描来自其他模块的控制器。我尝试了@ComponentScan注释,但没有解决我的问题。 问题是,这个想
-root
|-核心
|-项目2
|-项目3
所以我有3个独立的模块。我希望模块proj2和proj3是一种具有唯一控制器的外观,但是它们都应该继承自核心项目,服务和DAO将位于该项目,以便我可以@Autowire
它们。现在,当我将包含@SpringBootApplication
的Application.java
放入核心模块时,Spring不会扫描来自其他模块的控制器。我尝试了@ComponentScan
注释,但没有解决我的问题。
问题是,这个想法有意义吗?如果是,那么如何解决控制器的映射问题
编辑:
更复杂的树:
+演示
|+核心
|-src
|-main/java/com/demo/DemoApplication.java
|-格拉德尔酒店
|+proj1
|-src
|-main/java/com/demo/controller/DemoController.java
|-proj1.gradle
|+项目2
|-build.gradle
build.gradle:
buildscript {
ext {
springBootVersion = '2.0.3.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
allprojects {
apply plugin: 'java'
group = 'com.example'
version = '0.0.1-SNAPSHOT'
repositories {
mavenCentral()
}
}
subprojects {
apply plugin: 'org.springframework.boot'
sourceCompatibility = 1.8
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
project(':proj1') {
dependencies {
compile project(':core')
}
}
project(':proj2') {
dependencies {
compile project(':core')
}
}
core.gradle,proj1.gradle
dependencies {
compile(
[group: 'org.springframework.boot', name: 'spring-boot-starter', version: springBootVersion],
[group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: springBootVersion],
)
testCompile group: 'junit', name: 'junit', version: '4.12'
}
DemoApplication.java
package com.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
DemoController.java
package com.demo.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping("/demo")
public class DemoController {
@GetMapping
@ResponseBody
public String testMethod() {
return "Inside test method";
}
}
发布你的代码。渐变构建、应用程序类、控制器。与他们的包声明。