gpt4 book ai didi

SpringBoot : Unable to find a single main class from the following candidates

转载 作者:IT老高 更新时间:2023-10-28 13:51:08 34 4
gpt4 key购买 nike

我使用 Spring Initializer、嵌入式 Tomcat、Thymeleaf 模板引擎生成了一个 Spring Boot Web 应用程序。使用的技术:Spring Boot 1.4.2.RELEASE、Spring 4.3.4.RELEASE、Thymeleaf 2.1.5.RELEASE、Tomcat 嵌入 8.5.6、Maven 3、Java 8

我有一个 SpringBoot 应用程序。使用这两个类:

@Profile("!war")
@SpringBootApplication
@Import({SecurityConfig.class ,PersistenceConfig.class, ServiceConfig.class})
public class BookApplication {

public static void main(String[] args) {
SpringApplication.run(BookApplication.class, args);
}
}

@Profile("war")
@Import({SecurityConfig.class ,PersistenceConfig.class})
@SpringBootApplication
public class BookApplicationWar extends SpringBootServletInitializer {

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(BookApplicationWar.class);
}

public static void main(String[] args) throws Exception {
SpringApplication.run(BookApplicationWar.class, args);
}

}

我用这个命令生成 war

 mvn clean package -DskipTests -Dspring.profiles.active=pebloc,war -DAPP-KEY=pebloc

但是我收到了这个错误:

[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.5.2.RELEASE:repackage (default) on project book: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:1.5.2.RELEASE:repackage failed: Unable to find a single main class from the following candidates [com.tdk.BookApplication, com.tdk.BookApplicationWar] -> [Help 1]

最佳答案

如果你有多个主类,你需要明确地configure the main class在每个配置文件中:

<profiles>
<profile>
<id>profile1</id>
<properties>
<spring.boot.mainclass>com.SomeClass</spring.boot.mainclass>
</properties>
</profile>
<profile>
<id>profile2</id>
<properties>
<spring.boot.mainclass>com.SomeOtherClass</spring.boot.mainclass>
</properties>
</profile>
</profiles>

...

<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.2.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<mainClass>${spring.boot.mainclass}</mainClass>
</configuration>
</execution>
</executions>
...
</plugin>

spring-boot:repackage

关于SpringBoot : Unable to find a single main class from the following candidates,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42840576/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com