No bean named 'xxxxxxx' available--springboot 上線打war包


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!");
    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM