Java spring import error

I downloaded spring-framework-4.1.6.RELEASE from http://maven.springframework.org/release/org/springframework/spring/

Then I went to the Spring Website http://spring.io/guides/gs/rest-service/ to start a project, but I found there was a problem in it.

//The import org.springframework.boot cannot be resolved
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

      

It can't seem to find the jar files, so it can't import it, but I add all the jar files to create the path.
How can I solve this? Are Spring and SpringFramework the same?

+3


source to share


5 answers


It looks like you are trying to access the classes that are part of the Spring Boot project, maybe your Spring libraries do not contain the libraries of the project related w760> projects.

Naturally, I would recommend that you import it via Maven or Gradle as suggested by Spring Boot Quickstart.

But if you want to add it manually, the latest jar currently for SpringApplication

would be spring-boot-1.2.3.RELEASE.jar

Find HERE



And the class SpringBootApplication

is in spring-boot-autoconfigure-1.2.3.RELEASE.jar

Find HERE

So, check if you have similar jars among your current ones and load them if not, also remember, since you are dealing with dependencies manually, it is quite possible that these two new libraries will have their own dependencies and you will have to adapt to him.

+8


source


I got the problem that just anything in the org.springframework.boot.autoconfigure package. * failed to resolve / compile although proper jar was included in the classpath.

My solution: wipe the local maven repository

Running the command line "mvn clean compile" showed me a line like



[ERROR] error reading /Users/greyshine/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/1.4.3.RELEASE/spring-boot-autoconfigure-1.4.3.RELEASE.jar; invalid LOC header (bad signature)

      

This gave me the assumption that the artifact was not loaded correctly in the first run. I destroyed my maven spring boot repository artefacts (ie located at ~ / Users / MYHOME / .m2 / repository / org / springframework / boot), then I rebuild with mvn clean compile and it all worked.

+3


source


Spring framework zip

The artifact you downloaded from the maven repo doesn't have a jar Spring boot

, so it won't compile. Download spring boot jar and add it to your classpath.

This link has a definite maven dependency.

http://projects.spring.io/spring-boot/

+1


source


I had a similar problem and fixed it by tweaking the pom.xml

from

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

      

in

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

      

0


source


As an alternative to Dirk Schumacher's approach of deleting the entire local maven repository, I only delete the .m2 / repository / org / springframework folder to force that part to reload.

-1


source







All Articles