在springboot中怎么创建含有多个module的工程
这篇文章主要介绍在springboot中怎么创建含有多个module的工程,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

成都创新互联-专业网站定制、快速模板网站建设、高性价比庐江网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式庐江网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖庐江地区。费用合理售后完善,10余年实体公司更值得信赖。
栗子中含有两个 module,一个作为libarary. 工程,另外一个是主工程,调用libary .其中libary jar有一个服务,main工程调用这个服务。
创建根工程
创建一个maven 工程,其pom文件为:
4.0.0 com.forezp springboot-multi-module 0.0.1-SNAPSHOT pom springboot-multi-module Demo project for Spring Boot
需要注意的是packaging标签为pom 属性。
创建libary工程
libary工程为maven工程,其pom文件的packaging标签为jar 属性。创建一个service组件,它读取配置文件的 service.message属性。
@ConfigurationProperties("service")
public class ServiceProperties {
/**
* A message for the service.
*/
private String message;
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}提供一个对外暴露的方法:
@Configuration
@EnableConfigurationProperties(ServiceProperties.class)
public class ServiceConfiguration {
@Bean
public Service service(ServiceProperties properties) {
return new Service(properties.getMessage());
}
}创建一个springbot工程
引入相应的依赖,创建一个web服务:
@SpringBootApplication
@Import(ServiceConfiguration.class)
@RestController
public class DemoApplication {
private final Service service;
@Autowired
public DemoApplication(Service service) {
this.service = service;
}
@GetMapping("/")
public String home() {
return service.message();
}
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}在配置文件application.properties中加入:
service.message=Hello World
打开浏览器访问:http://localhost:8080/;浏览器显示:
Hello World
说明确实引用了libary中的方法。
以上是“在springboot中怎么创建含有多个module的工程”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联行业资讯频道!
本文题目:在springboot中怎么创建含有多个module的工程
URL链接:http://www.jxjierui.cn/article/isppeg.html


咨询
建站咨询
