有两个像下面这样的spring-boot项目:
service_one
service_two
所有人都可以独自成功。
现在,我已经改变了这种方式,我使用service_all
项目来管理应该运行哪些服务:例如jvm属性。最后的项目就像之后
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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.demo.service</groupId>
<artifactId>service_all</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>service_all</name>
<dependencies>
<dependency>
<groupId>com.demo.service</groupId>
<artifactId>service_one</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.demo.service</groupId>
<artifactId>service_two</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.0.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
// Java class in service_all
@Slf4j
@SpringBootApplication
public class Application {
public static void main(String[] args) throws IOException {
/**
* Common
*/
ConfigurableApplicationContext commonContext =
new SpringApplicationBuilder(Application.class).web(WebApplicationType.NONE).run(args);
log.info(commonContext.getId() + " isActive: " + commonContext.isActive());
/**
* service_one
*/
if (commonContext.getEnvironment().containsProperty("service_one")) {
ConfigurableApplicationContext oneContext =
new SpringApplicationBuilder(ServiceOneApplication.class)
.parent(commonContext)
.sources(RefreshScope.class).run(args);
log.info(configContext.getId() + " isActive: " + oneContext.isActive());
}
/**
* service_two
*/
if (commonContext.getEnvironment().containsProperty("service_two")) {
ConfigurableApplicationContext twoContext =
new SpringApplicationBuilder(ServiceTwoApplication.class).parent(commonContext)
.sources(RefreshScope.class).run(args);
log.info(adminContext.getId() + " isActive: " + twoContext.isActive());
}
}
}
现在我无法将service_one
和service_two
lib打包到service_all
jar的lib中。
那我该如何解决呢?
PS:
service_one
和service_two
的任何东西,只能像依赖项一样使用;