10

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);
    }
}
Steven Hachel
  • 101
  • 1
  • 1
  • 6

6 Answers6

5

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>
  • @Suresh , can you help in this issue ? https://stackoverflow.com/q/57393814/3301316 – Jet Aug 08 '19 at 05:12
4

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

Bwvolleyball
  • 2,593
  • 2
  • 19
  • 31
  • How can I influence this? I would just like to work with the current version of Spring ... – Steven Hachel Oct 27 '16 at 08:42
  • I edited the answer to show what your main method would look like. You aren't required to store the results of the SpringApplicationBuilder() in a variable,I simply put it there to show you how that would be done. – Bwvolleyball Oct 27 '16 at 12:49
  • @Bwvolleyball, can you help in this issue ? https://stackoverflow.com/q/57393814/3301316 – Jet Aug 08 '19 at 05:12
2

I was also getting the same problem while setting up dummy Producer- consumer microservice.

Adding below changes in Pom.xml ,was able to solve my problem.

<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>
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
rahulnikhare
  • 1,362
  • 1
  • 18
  • 25
0

Check out your Cloud dependencies. I had the same problem and just organize my cloud dependencies goes well. If you dont use cloud, just exclude cloud transitive dependencies from pom.

0

I was also facing the same problem in maven based project while testing the demo for JWT project.

I just removed the version from dependency like below-

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
</dependency>

by doing this maven dependency resolver takes the default supported version.

Earlier I was mentioning version 2.1.3.RELEASE explicitly which caused issue and then I removed the version then it took by default 2.0.3.RELEASE and worked for me.

Issue resolved. !!!!!!!!!!!!!!!!!

Arvind Kumar
  • 459
  • 5
  • 21
0

You get different errors if you use incompatible versions of libraries. So, before doing any troubleshooting, check the versions and make sure to use the compatible versions.

You can refer the below link to check what versions are compatible.

http://start.spring.io/actuator/info

Got this link from one of the SO answers itself: Is there a compatibility matrix of Spring-boot and Spring-cloud?

Madhu
  • 71
  • 1
  • 5