Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

1.3.7.RELEASE -> 1.4.1.RELEASE | java.lang.NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder.showBanner

If I switch to the new version of SpringBoot, I get the above error message when starting the application. Why is that?

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);
    }
}
like image 711
Steven Hachel Avatar asked Oct 26 '16 09:10

Steven Hachel


2 Answers

I was able to resolve this by explicitly declaring the cloud-context dependency which works for version 1.4.4

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-context</artifactId>
        <version>1.1.8.RELEASE</version>
    </dependency>
like image 163
Suresh nithyanandam Avatar answered Nov 11 '22 16:11

Suresh nithyanandam


When working with Spring Boot 1.4.1.RELEASE, they have changed it from

new SpringApplicationBuilder().showBanner()

to

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

where Banner.Mode bannerModeexpects an enum for either: Console, Log, or Off.

examples:

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

If you are looking for the banner to be printed, go with the first one, Banner.Mode.CONSOLE

Your new main method would look like this:

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.)
}

Here is the java doc to the SpringApplicationBuilder:

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

And here is the java doc explaining the Banner.Mode Enum:

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

like image 4
Bwvolleyball Avatar answered Nov 11 '22 15:11

Bwvolleyball