springboot项目发布上线后,报错:No bean named 'xxxxxxx' available
因为我开发时pom用的jar,但上线发布war。解决方法:
1、pom.xml
<packaging>war</packaging>
将tomcat从boot中提出来,并将scope设置为provide
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency>
2、ApplicationWar
@EnableTransactionManagement @SpringBootApplication @ComponentScan(basePackages="com.gomepay.goa") @ServletComponentScan(basePackages = "com.gomepay.goa") @EnableAutoConfiguration @Slf4j public class ApplicationWar extends SpringBootServletInitializer { /** * 为了将springboot程序在tomcat中运行 */ @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(ApplicationWar.class); } public static void main(String[] args) { SpringApplication app = new SpringApplication(ApplicationWar.class); app.setBannerMode(Banner.Mode.OFF); app.run(args); log.info("PortalApplication is success!"); } }