Run from the command line with profiles serverandclient
To use the same entry point and the same entry point with two different profiles, you just need to provide the Spring profile at run time so that a different application is loaded - $ {profile} .properties (and possibly the conditional Java configuration was launched).
2 Spring determine profiles ( clientand server) :
- Each of them will have its own.
application-${profile}.properties - Client Properties Disable Web Container
You have one SpringBootApp and an entry point :
@SpringBootApplication
public class SpringBootApp {
public static void main(String[] args) {
new SpringApplicationBuilder()
.sources(SpringBootApp.class)
.run(args);
}
}
Make this class your primary class.
SRC/// application-server.properties
spring.application.name=server
server.port=8080
SRC/// application-client.properties
spring.application.name=client
spring.main.web-environment=false
:
$ java -jar -Dspring.profiles.active=server YourApp.jar
$ java -jar -Dspring.profiles.active=client YourApp.jar
@Configuration, :
@Configuration
@Profile("client")
public class ClientConfig {
}
IDE server client
@SpringBootApplication
public class SpringBootApp {
}
public class LauncherServer {
public static void main(String[] args) {
new SpringApplicationBuilder()
.sources(SpringBootApp.class)
.profiles("server")
.run(args);
}
}
public class ClientLauncher {
public static void main(String[] args) {
new SpringApplicationBuilder()
.sources(SpringBootApp.class)
.profiles("client")
.web(false)
.run(args);
}
}
( ):
new SpringApplicationBuilder()
.sources(SpringBootApp.class, ClientSpecificConfiguration.class)
.profiles("client")
.web(false)
.run(args);
SRC/// application-server.properties
spring.application.name=server
server.port=8080
SRC/// application-client.properties
spring.application.name=client
: 2 SpringBootApp (ClientSpringBootApp, ServerSpringBootApp), , AutoConfiguration ComponentScan:
@SpringBootApplication
@ComponentScan("...")
public class ServerSpringBootApp {
public static void main(String[] args) {
new SpringApplicationBuilder()
.sources(ServerSpringBootApp.class)
.profiles("server")
.run(args);
}
}
@SpringBootApplication(exclude = SecurityAutoConfiguration.class)
@ComponentScan("...")
public class ClientSpringBootApp {
public static void main(String[] args) {
new SpringApplicationBuilder()
.sources(ClientSpringBootApp.class)
.profiles("client")
.web(false)
.run(args);
}
}