4

This is my main application code:

package u.d.dip.rs.app;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;

@EnableWebSecurity
@SpringBootApplication
@ComponentScan(basePackages = "u.d.dip")
@EnableAutoConfiguration
public class DipApplication {
    public static void main(String[] args) {
        SpringApplication.run(DipApplication.class, args);
    }
}

I'm using gradle to build the project. Even though SpringApplication file is properly imported I'm getting the following error:

Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 6 more

Process finished with exit code 1

I'm getting following gradle message when I hover over SpringApplication

[Gradle: org.springframework.boot:spring-boot:1.5.1.RELEASE] org.springframework.boot public class SpringApplication extends Object

Any help would be much appreciated. Thanks in advance!

6
  • I'm not sure if its a typo only here but your class name is DigApplication - Dig with a g and you try to run DipApplication - Dip with a p. Also, @EnableAutoConfiguration is not needed when you use @SpringBootApplication as it already contains it. Commented Mar 6, 2017 at 15:24
  • Do a gradle clean build and you should run application Commented Mar 6, 2017 at 19:35
  • @Tom Thanks for pointing out the typo. I've edited the question. But that's not what is causing the error. Commented Mar 7, 2017 at 7:48
  • How do you run your application? How is gradle relevant? Commented Mar 7, 2017 at 7:49
  • @JBNizet Gradle is important because I'm resolving all my dependencies through that. Since the kind of error that I'm getting is because of spring-boot related issue, which is available as an external library in my project. Commented Mar 7, 2017 at 8:36

5 Answers 5

4

If you are using IntelliJ Idea, the new version 2016.3.6 solved this issue.

Sign up to request clarification or add additional context in comments.

Comments

2

The error was because of an issue with gradle 3.4 I've changed my gradle distribution to 3.2 and everything is working fine now.

Please refer this for more information: https://github.com/gradle/gradle/issues/1335

Hope this solves your problem.

Comments

1

I fix this error by change gradle3.4 to 3.2

Comments

1

i encountered this problem too, just with another story.

i am using spring boot 2.2.5 and gradle 5.1.2.

run gradle build -x test, it will tell you what error it is.

in my case, it told me that error: package org.jasig.cas.client.authentication does not exist, but this package exists in fact.

then i remembered that i added a dependency runtimeOnly 'org.apereo.cas:cas-server-support-validation:5.3.15.1'

after comment this dependency, my project can start success.

Comments

0

I understand this is an old thread, but still adding an answer.

Spring Boot will add two jars under build\libs\ (once we execute ./gradlew clean build or equivalent) *.jar(this will be jar with all dependencies) and *-plain.jar(will not have any dependencies). Now *-plain.jar is getting picked up and executed and causing No manifest and Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication (once we fix no manifest by providing manifest under jar {}).

We need to run *.jar using java -jar command. If we want to stop generating *-plain.jar , we have to simply add following in our build.gradle :

jar {
enabled = false
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.