Java B2B2C多用户商城 springboot架构 (二十二)建立含有多module的springboot工程

这篇文章主要介绍如何在springboot中如何建立含有多个module的工程,栗子中含有两个 module,一个做为libarary. 工程,另一个是主工程,调用libary .其中libary jar有一个服务,main工程调用这个服务。java

建立根工程

建立一个maven 工程,其pom文件为:web

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
 
    <groupId>com.forezp</groupId>
    <artifactId>springboot-multi-module</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>
    <name>springboot-multi-module</name>
    <description>Demo project for Spring Boot</description>
 
 
 
</project>

须要注意的是packaging标签为pom 属性。spring

建立libary工程

libary工程为maven工程,其pom文件的packaging标签为jar 属性。建立一个service组件,它读取配置文件的 service.message属性。apache

@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;
    }
}

提供一个对外暴露的方法:springboot

@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);
    }
}

架构代码以下:app

"分布式b2b <wbr

须要JAVASpring Cloud大型企业分布式微服务云构建的B2B2C电子商务平台源码请加企鹅求求:一零三八七七四六二六 maven

相关文章
相关标签/搜索