Skip to content

Commit 5566fd3

Browse files
Kehrlannjgrandja
authored andcommitted
SpringApplicationBuilder instead of threads
1 parent d527cd2 commit 5566fd3

File tree

3 files changed

+50
-11
lines changed

3 files changed

+50
-11
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package sample;
2+
3+
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
4+
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
5+
import org.springframework.context.annotation.Bean;
6+
import org.springframework.context.annotation.Configuration;
7+
8+
@Configuration
9+
public class Customizer {
10+
@Bean
11+
WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> portCustomizer() {
12+
return factory -> factory.setPort(1234);
13+
}
14+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package sample;
2+
3+
import org.springframework.boot.builder.SpringApplicationBuilder;
4+
import org.springframework.context.ConfigurableApplicationContext;
5+
import sample.resourceserver.ResourceServerApplication;
6+
7+
public class Main {
8+
9+
public static void main(String[] args) throws InterruptedException {
10+
ConfigurableApplicationContext authz = new SpringApplicationBuilder(OAuth2AuthorizationServerApplication.class)
11+
.application()
12+
.run();
13+
ConfigurableApplicationContext resource = new SpringApplicationBuilder(ResourceServerApplication.class)
14+
.application()
15+
.run();
16+
17+
Thread.sleep(5000);
18+
System.out.println("STOP ! Hammertime.");
19+
20+
authz.stop();
21+
resource.stop();
22+
System.out.println("bye");
23+
}
24+
}

β€Žsamples/boot/oauth2-integration/authorizationserver/src/main/java/sample/OAuth2AuthorizationServerApplication.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,30 @@
2020
import org.springframework.boot.CommandLineRunner;
2121
import org.springframework.boot.SpringApplication;
2222
import org.springframework.boot.autoconfigure.SpringBootApplication;
23+
import org.springframework.boot.builder.SpringApplicationBuilder;
2324
import sample.resourceserver.ResourceServerApplication;
2425

2526
/**
2627
* @author Joe Grandja
2728
* @since 0.0.1
2829
*/
2930
@SpringBootApplication(scanBasePackages = {"sample.config"})
30-
public class OAuth2AuthorizationServerApplication implements CommandLineRunner {
31+
public class OAuth2AuthorizationServerApplication {
3132

3233
private final Logger logger = LoggerFactory.getLogger(OAuth2AuthorizationServerApplication.class);
33-
private Thread resourceServerThread;
34+
// private Thread resourceServerThread;
3435

3536
public static void main(String[] args) {
3637
SpringApplication.run(OAuth2AuthorizationServerApplication.class, args);
3738
}
3839

39-
@Override
40-
public void run(String... args) {
41-
logger.info("Hello πŸ₯°πŸ₯³");
42-
resourceServerThread = new Thread(
43-
() -> SpringApplication.run(ResourceServerApplication.class, new String[]{})
44-
);
45-
resourceServerThread.start();
46-
logger.info("Running πŸƒπŸ‘Ÿβ€");
47-
}
40+
// @Override
41+
// public void run(String... args) {
42+
// logger.info("Hello πŸ₯°πŸ₯³");
43+
// resourceServerThread = new Thread(
44+
// () -> SpringApplication.run(ResourceServerApplication.class, new String[]{})
45+
// );
46+
// resourceServerThread.start();
47+
// logger.info("Running πŸƒπŸ‘Ÿβ€");
48+
// }
4849
}

0 commit comments

Comments
Β (0)