Skip to content

Commit 26c3d0f

Browse files
committed
SpringBootApplicationMain->GenericSpringBootApplicationMain
Closes gh-87
1 parent e5a01c5 commit 26c3d0f

File tree

6 files changed

+23
-16
lines changed

6 files changed

+23
-16
lines changed

README.adoc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@ repositories.add(new RemoteRepository.Builder("spring-milestone", "default", "ht
118118
MavenClasspathEntry classpathEntry = new MavenClasspathEntry("org.springframework:spring-core:6.1.0-RC1", repositories);
119119
----
120120

121-
=== Default Java Main
121+
=== GenericSpringBootApplicationMain
122122

123-
In some cases you need to provide a Java main class without any additional configuration.
124-
If that is the case, you can do it with the following:
123+
For adhoc applications, you may not have a main class and you may not want to provide boilerplate main method yourself.
124+
If that is the case, you can leverage `useGenericSpringBootMain`:
125125

126126
[source,java]
127127
----
@@ -131,8 +131,8 @@ static CommonsExecWebServerFactoryBean authorizationServer() {
131131
// @formatter:off
132132
return CommonsExecWebServerFactoryBean.builder()
133133
// ...
134-
// Add a class annotated with SpringBootApplication and a main method to the classpath and use it as the main class
135-
.defaultSpringBootApplicationMain();
134+
// Add a generic class annotated with SpringBootApplication and a main method to the classpath and use it as the main class
135+
.useGenericSpringBootMain();
136136
// @formatter:on
137137
}
138138
----
@@ -156,7 +156,7 @@ For example, if someone wants to start a Config Server instance, the `ConfigServ
156156
static CommonsExecWebServerFactoryBean configServer() {
157157
// @formatter:off
158158
return CommonsExecWebServerFactoryBean.builder()
159-
.defaultSpringBootApplicationMain()
159+
.useGenericSpringBootMain()
160160
.setAdditionalBeanClassNames("org.springframework.cloud.config.server.config.ConfigServerConfiguration")
161161
.classpath((classpath) -> classpath
162162
.entries(springBootStarter("web"))

config/checkstyle/checkstyle-suppressions.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
<suppressions>
66
<!-- Ignore third-party code -->
77
<suppress files="LoggingMavenRepositoryListener\.java|LoggingMavenTransferListener\.java" checks=".*"/>
8-
<suppress files="SpringBootApplicationMain\.java" checks=".*"/>
8+
<suppress files="GenericSpringBootApplicationMain\.java" checks=".*"/>
99
<suppress files="SpringBootFatJarMain\.java" checks=".*"/>
1010
</suppressions>

samples/oauth2-login/src/test/java/example/oauth2/login/TestOauth2LoginMain.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class TestOauth2LoginMain {
3232
static CommonsExecWebServerFactoryBean authorizationServer() {
3333
// @formatter:off
3434
return CommonsExecWebServerFactoryBean.builder()
35-
.defaultSpringBootApplicationMain()
35+
.useGenericSpringBootMain()
3636
.classpath((classpath) -> classpath
3737
.entries(springBootStarter("oauth2-authorization-server"))
3838
);

spring-boot-testjars-maven/src/test/java/org/springframework/experimental/boot/test/context/MavenClasspathTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static class Configuration {
5252
static CommonsExecWebServerFactoryBean authorizationServer() {
5353
// @formatter:off
5454
return CommonsExecWebServerFactoryBean.builder()
55-
.defaultSpringBootApplicationMain()
55+
.useGenericSpringBootMain()
5656
.classpath((classpath) -> classpath
5757
.entries(springBootStarter("oauth2-authorization-server"))
5858
);

spring-boot-testjars/src/main/java/org/springframework/experimental/boot/server/exec/CommonsExecWebServerFactoryBean.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import org.springframework.beans.factory.BeanNameAware;
3030
import org.springframework.beans.factory.DisposableBean;
3131
import org.springframework.beans.factory.SmartFactoryBean;
32-
import org.springframework.experimental.boot.server.exec.imports.SpringBootApplicationMain;
32+
import org.springframework.experimental.boot.server.exec.imports.GenericSpringBootApplicationMain;
3333
import org.springframework.util.Assert;
3434
import org.springframework.util.ClassUtils;
3535
import org.springframework.util.StringUtils;
@@ -48,7 +48,7 @@ public class CommonsExecWebServerFactoryBean
4848

4949
private static Log logger = LogFactory.getLog(CommonsExecWebServerFactoryBean.class);
5050

51-
private static final String DEFAULT_SPRING_BOOT_MAIN_CLASSNAME = SpringBootApplicationMain.class.getName();
51+
private static final String GENERIC_SPRING_BOOT_MAIN_CLASSNAME = GenericSpringBootApplicationMain.class.getName();
5252

5353
private String executable = currentJavaExecutable();
5454

@@ -87,9 +87,9 @@ private static File createApplicationPortFile() {
8787
}
8888
}
8989

90-
public CommonsExecWebServerFactoryBean defaultSpringBootApplicationMain() {
91-
mainClass(DEFAULT_SPRING_BOOT_MAIN_CLASSNAME);
92-
Class<?> mainClass = ClassUtils.resolveClassName(DEFAULT_SPRING_BOOT_MAIN_CLASSNAME, null);
90+
public CommonsExecWebServerFactoryBean useGenericSpringBootMain() {
91+
mainClass(GENERIC_SPRING_BOOT_MAIN_CLASSNAME);
92+
Class<?> mainClass = ClassUtils.resolveClassName(GENERIC_SPRING_BOOT_MAIN_CLASSNAME, null);
9393
return classpath((classpath) -> classpath.scan(mainClass));
9494
}
9595

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,18 @@
1919
import org.springframework.boot.SpringApplication;
2020
import org.springframework.boot.autoconfigure.SpringBootApplication;
2121

22+
/**
23+
* Convenience main method that can be leveraged by adhoc applications that do not have a
24+
* main method.
25+
*
26+
* @author Rob Winch
27+
* @see org.springframework.experimental.boot.server.exec.CommonsExecWebServerFactoryBean#useGenericSpringBootMain()
28+
*/
2229
@SpringBootApplication
23-
public class SpringBootApplicationMain {
30+
public class GenericSpringBootApplicationMain {
2431

2532
public static void main(String[] args) {
26-
SpringApplication spring = new SpringApplication(SpringBootApplicationMain.class);
33+
SpringApplication spring = new SpringApplication(GenericSpringBootApplicationMain.class);
2734
spring.addInitializers(new RegisterBeanDefinitionsInitializer());
2835
spring.run(args);
2936
}

0 commit comments

Comments
 (0)