BAEL-6532: Define main class when using multiple profiles in a Spring Boot project (#14267)
Co-authored-by: Tapan Avasthi <tavasthi@Tapans-MacBook-Air.local>
This commit is contained in:
parent
7e07ee0bea
commit
c54937de56
|
@ -1,7 +1,7 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>spring-boot-basic-customization</artifactId>
|
<artifactId>spring-boot-basic-customization</artifactId>
|
||||||
<name>spring-boot-basic-customization</name>
|
<name>spring-boot-basic-customization</name>
|
||||||
|
@ -39,4 +39,50 @@
|
||||||
<start-class>com.baeldung.changeport.CustomApplication</start-class>
|
<start-class>com.baeldung.changeport.CustomApplication</start-class>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
<profiles>
|
||||||
|
<profile>
|
||||||
|
<id>errorhandling</id>
|
||||||
|
<properties>
|
||||||
|
<spring.boot.mainclass>com.baeldung.errorhandling.ErrorHandlingApplication</spring.boot.mainclass>
|
||||||
|
</properties>
|
||||||
|
</profile>
|
||||||
|
<profile>
|
||||||
|
<id>filter</id>
|
||||||
|
<properties>
|
||||||
|
<spring.boot.mainclass>com.baeldung.bootcustomfilters.SpringBootFiltersApplication</spring.boot.mainclass>
|
||||||
|
</properties>
|
||||||
|
</profile>
|
||||||
|
<profile>
|
||||||
|
<id>customapplication</id>
|
||||||
|
<properties>
|
||||||
|
<spring.boot.mainclass>com.baeldung.changeport.CustomApplication</spring.boot.mainclass>
|
||||||
|
</properties>
|
||||||
|
</profile>
|
||||||
|
<profile>
|
||||||
|
<id>failureanalyzer</id>
|
||||||
|
<properties>
|
||||||
|
<spring.boot.mainclass>com.baeldung.failureanalyzer.FailureAnalyzerApplication</spring.boot.mainclass>
|
||||||
|
</properties>
|
||||||
|
</profile>
|
||||||
|
<profile>
|
||||||
|
<id>favicon</id>
|
||||||
|
<properties>
|
||||||
|
<spring.boot.mainclass>com.baeldung.favicon.FaviconApplication</spring.boot.mainclass>
|
||||||
|
</properties>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<version>1.5.2.RELEASE</version>
|
||||||
|
<configuration>
|
||||||
|
<mainClass>${spring.boot.mainclass}</mainClass>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -2,13 +2,15 @@ package com.baeldung.bootcustomfilters;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.context.annotation.Profile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Boot application
|
* Boot application
|
||||||
* @author hemant
|
* @author hemant
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@SpringBootApplication
|
@Profile("filter")
|
||||||
|
@SpringBootApplication(scanBasePackages = "com.baeldung.bootcustomfilters.*")
|
||||||
public class SpringBootFiltersApplication {
|
public class SpringBootFiltersApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
|
@ -4,8 +4,10 @@ import java.util.Collections;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.context.annotation.Profile;
|
||||||
|
|
||||||
@SpringBootApplication
|
@Profile("customapplication")
|
||||||
|
@SpringBootApplication(scanBasePackages = "com.baeldung.changeport")
|
||||||
public class CustomApplication {
|
public class CustomApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
|
@ -2,7 +2,9 @@ package com.baeldung.errorhandling;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.context.annotation.Profile;
|
||||||
|
|
||||||
|
@Profile("errorhandling")
|
||||||
@SpringBootApplication(scanBasePackages = "com.baeldung.errorhandling")
|
@SpringBootApplication(scanBasePackages = "com.baeldung.errorhandling")
|
||||||
public class ErrorHandlingApplication {
|
public class ErrorHandlingApplication {
|
||||||
|
|
||||||
|
|
|
@ -2,10 +2,12 @@ package com.baeldung.failureanalyzer;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.context.annotation.Profile;
|
||||||
|
|
||||||
import javax.annotation.security.RolesAllowed;
|
import javax.annotation.security.RolesAllowed;
|
||||||
|
|
||||||
@SpringBootApplication
|
@Profile("failureanalyzer")
|
||||||
|
@SpringBootApplication(scanBasePackages = "com.baeldung.failureanalyzer")
|
||||||
public class FailureAnalyzerApplication {
|
public class FailureAnalyzerApplication {
|
||||||
@RolesAllowed("*")
|
@RolesAllowed("*")
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
|
@ -2,8 +2,10 @@ package com.baeldung.favicon;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.context.annotation.Profile;
|
||||||
|
|
||||||
@SpringBootApplication
|
@Profile("favicon")
|
||||||
|
@SpringBootApplication(scanBasePackages = "com.baeldung.favicon")
|
||||||
public class FaviconApplication {
|
public class FaviconApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
package com.baeldung.failureanalyzer;
|
package com.baeldung.failureanalyzer;
|
||||||
|
|
||||||
import ch.qos.logback.classic.spi.ILoggingEvent;
|
import ch.qos.logback.classic.spi.ILoggingEvent;
|
||||||
|
|
||||||
import com.baeldung.failureanalyzer.utils.ListAppender;
|
import com.baeldung.failureanalyzer.utils.ListAppender;
|
||||||
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.BeanCreationException;
|
import org.springframework.beans.factory.BeanCreationException;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Properties;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
@ -27,7 +30,11 @@ public class FailureAnalyzerAppIntegrationTest {
|
||||||
@Test
|
@Test
|
||||||
public void givenBeanCreationErrorInContext_whenContextLoaded_thenFailureAnalyzerLogsReport() {
|
public void givenBeanCreationErrorInContext_whenContextLoaded_thenFailureAnalyzerLogsReport() {
|
||||||
try {
|
try {
|
||||||
SpringApplication.run(FailureAnalyzerApplication.class);
|
Properties properties = new Properties();
|
||||||
|
properties.setProperty("spring.profiles.active", "failureanalyzer");
|
||||||
|
SpringApplication app = new SpringApplication(FailureAnalyzerApplication.class);
|
||||||
|
app.setDefaultProperties(properties);
|
||||||
|
app.run();
|
||||||
} catch (BeanCreationException e) {
|
} catch (BeanCreationException e) {
|
||||||
Collection<String> allLoggedEntries = ListAppender.getEvents()
|
Collection<String> allLoggedEntries = ListAppender.getEvents()
|
||||||
.stream()
|
.stream()
|
||||||
|
|
Loading…
Reference in New Issue