1.项目结构如下
步骤如下:
点击Finish
这里父项目需要加入如下的构建依赖:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-releasetrain</artifactId>
<version>Fowler-SR2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.0.2.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
再加入springboot的依赖:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
2.构建子项目
点击next修改名称完成构建 这里我们把a-first当做启动项目,需要在maven中加入:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
然后加入启动类:
@SpringBootApplication
@ComponentScan("com.test.*")
public class AfirstApplication {
public static void main(String[] args) {
SpringApplication.run(AfirstApplication.class);
}
}
b项目的建立
用同样的方式建立b项目 但不用建立启动类,我们项目a依赖b,如下:
在b中建立包com.test.bsecond,下面建立类TestRead:
public class TestRead {
public String eat(){
return "test eat";
}
}
在a中建立包com.test.afirst,下面建立包test,再建立类AReadB:
@Controller
public class AReadB {
@RequestMapping("/test")
@ResponseBody
public String test() {
TestRead testRead = new TestRead();
String eat = testRead.eat();
return eat;
}
}
现在执行mvn install,这个项目下面的所有的都打包完毕
然后我们运行启动类的jar包:
访问路径:http://localhost:8080/test 结果如下:
test eat
原文地址:https://www.cnblogs.com/charlypage/p/10952864.html
时间: 2024-10-11 21:12:26