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

2019/01/21 19:10
阅读数 1.1K

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

 

展开阅读全文
打赏
0
0 收藏
分享
加载中
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部