Netflix Zuul注释导致Spring Boot应用无法启动

时间:2018-09-12 15:22:45

标签: spring-boot netflix-zuul

spring-boot-starter-parent使用1.5.9

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.9.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

依赖性:

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
            <version>2.0.0.RELEASE</version>
        </dependency>

应用程序:

@RestController
@ComponentScan({"com.bmc.common.portal","com.bmc.common.portal.controllers","com.bmc.dem", "com.bmc.costportal.controllers", "com.bmc.cost.portal"})
@EnableZuulProxy
@SpringBootApplication
public class PortalApplication {

    @Bean
    public EmbeddedServletContainerCustomizer containerCustomizer() {

       return (container -> {
            ErrorPage error400Page = new ErrorPage(HttpStatus.BAD_REQUEST,"/error/400.html");
            ErrorPage error401Page = new ErrorPage(HttpStatus.UNAUTHORIZED,"/error/401.html");
            ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND,"/error/404.html");
            ErrorPage error500Page = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/error/500.html");
            container.addErrorPages(error400Page, error401Page,error404Page, error500Page); });
    }

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

错误:

  

[2018年9月12日20:36:26,702] [错误]   org.springframework.boot.SpringApplication:应用程序启动失败   java.lang.NoSuchMethodError:   org.springframework.boot.builder.SpringApplicationBuilder。([Ljava / lang / Class;)V           在org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:170)           在org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:104)           在org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:70)           在org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)           在org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)           在org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)           在org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122)           在org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74)           在org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)           在org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:325)           在org.springframework.boot.SpringApplication.run(SpringApplication.java:296)           在org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)           atorg.springframework.boot.SpringApplication.run(SpringApplication.java:1107)

1 个答案:

答案 0 :(得分:1)

您正在使用1.x分支中的spring-boot-starter-parent和2.x分支中的spring-cloud-starter-netflix-zuul。 2.x与1.x不兼容。尝试从2.x分支升级到spring-boot-starter-parent或将spring-cloud-starter-netflix-zuul降级到1.x