2016-10-26 20 views
5

Nếu tôi chuyển sang phiên bản mới của SpringBoot, tôi nhận được thông báo lỗi trên khi khởi động ứng dụng. Tại sao vậy?1.3.7.RELEASE -> 1.4.1.RELEASE | java.lang.NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder.showBanner

Best wishes Steven

pom.xml

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
<modelVersion>4.0.0</modelVersion> 

<groupId>de.xyz.microservice</groupId> 
<artifactId>spring-boot-test</artifactId> 
<version>1.0-SNAPSHOT</version> 

<parent> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-parent</artifactId> 
    <!--version>1.3.7.RELEASE</version--> 
    <version>1.4.1.RELEASE</version> 
</parent> 
<dependencies> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-web</artifactId> 
    </dependency> 
</dependencies> 

</project> 

stacktrace:

Exception in thread "main" java.lang.NoSuchMethodError: 
        org.springframework.boot.builder.SpringApplicationBuilder.showBanner(Z)Lorg/springframework/boot/builder/SpringApplicationBuilder; 
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:109) 
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:75)... 

MainClass:

@SpringBootApplication 
@ComponentScan(value = "de.xyzs.microservice") 
@EnableAspectJAutoProxy(proxyTargetClass = true) 

public class MainClass { 

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

Vui lòng thêm các chi tiết khác. –

+0

Tin nhắn ngoại lệ khá rõ ràng ... Bạn có điều gì 'NoSuchMethodError' là gì? ... –

+0

Tôi đã thêm tệp "pom.xml". :-) –

Trả lời

3

Khi làm việc với mùa xuân Boot 1.4.1.RELEASE, họ đã thay đổi nó từ

new SpringApplicationBuilder().showBanner()

để

new SpringApplicationBuilder().bannerMode(Banner.Mode bannerMode)

nơi Banner.Mode bannerMode hy vọng một enum cho một trong hai: Bảng điều khiển , Đăng nhập hoặc Tắt.

ví dụ:

new SpringApplicationBuilder().bannerMode(Banner.Mode.CONSOLE); //Prints banner to System.out 

new SpringApplicationBuilder().bannerMode(Banner.Mode.LOG); //Prints banner to the log file 

new SpringApplicationBuilder().bannerMode(Banner.Mode.OFF); //Disables the banner 

Nếu bạn đang tìm kiếm các biểu ngữ được in, đi với cái đầu tiên, Banner.Mode.CONSOLE

phương pháp chính mới của bạn sẽ trông như thế này:

public static void main(String[] args){ 

    //SpringApplicationBuilder() returns an ApplicationContext, but creating the variable is optional 
    ApplicationContext ctx = new SpringApplicationBuilder().bannerMode(Banner.Mode.CONSOLE).run(args); 

    //Now, if you need to do something else with the ApplicationContext, you can (such as print all the beans, etc.) 
} 

Đây là tài liệu java cho SpringApplicationBuilder:

http://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/builder/SpringApplicationBuilder.html#bannerMode-org.springframework.boot.Banner.Mode-

Và đây là doc java giải thích Banner.Mode Enum:

http://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/Banner.Mode.html

+0

Tôi có thể ảnh hưởng đến điều này như thế nào? Tôi chỉ muốn làm việc với phiên bản hiện tại của Spring ... –

+0

Tôi đã chỉnh sửa câu trả lời để hiển thị phương thức chính của bạn. Bạn không cần phải lưu trữ các kết quả của SpringApplicationBuilder() trong một biến, tôi chỉ cần đặt nó ở đó để chỉ cho bạn cách thực hiện điều đó. – Bwvolleyball

+0

Điều này không hiệu quả đối với tôi. – jDub9

0

Check-out đám mây phụ thuộc của bạn. Tôi đã có cùng một vấn đề và chỉ tổ chức phụ thuộc đám mây của tôi diễn ra tốt đẹp. Nếu bạn không sử dụng đám mây, chỉ cần loại trừ phụ thuộc đám mây chuyển tiếp từ pom.

2

tôi đã có thể giải quyết điều này bằng cách tuyên bố một cách rõ ràng phụ thuộc đám mây bối cảnh mà làm việc cho phiên bản 1.4.4

<dependency> 
     <groupId>org.springframework.cloud</groupId> 
     <artifactId>spring-cloud-context</artifactId> 
     <version>1.1.8.RELEASE</version> 
    </dependency> 
+0

thx! nó hoạt động! :-) –

+0

Điều này đã hiệu quả. Cảm ơn bạn! – jDub9

0

Tôi cũng đã nhận được cùng một vấn đề trong khi thiết lập giả Producer- microservice tiêu dùng.

Thêm các thay đổi bên dưới vào tệp Pom.xml, có thể giải quyết được sự cố của tôi.

<dependencyManagement> 
     <dependencies> 
      <dependency> 
       <groupId>org.springframework.cloud</groupId> 
       <artifactId>spring-cloud-dependencies</artifactId> 
       <version>Camden.SR6</version> 
       <type>pom</type> 
       <scope>import</scope> 
      </dependency> 
     </dependencies> 
    </dependencyManagement> 
Các vấn đề liên quan