我正在尝试在春天构建最简单的应用程序,我的单个控制器有以下代码
package User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* Created by Bula on 14/02/14.
*/
@Controller
public class UsersController {
@RequestMapping("/user")
public String index()
{
return "user_index";
}
}
这是Main.java。引导一切的那个:
package main;
import javafx.application.Application;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
@ComponentScan
@EnableAutoConfiguration
public class Main {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
这也是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>blog</groupId>
<artifactId>blog</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5.6</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
我已经更新了maven,因此技术上所有的库都应该存在。这是被抛出的错误(我尝试使用谷歌搜索但没有出现任何接近我所面临的情况):
Exception in thread "main" java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotationAwareOrderComparator.sort(Ljava/util/List;)V
at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:371)
at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:343)
at org.springframework.boot.SpringApplication.initialize(SpringApplication.java:221)
at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:197)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:877)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:866)
at main.Main.main(Main.java:14)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Process finished with exit code 1
我的user_index.html确实存在,但我不认为错误与它有任何关联,因为它只有一个html标记。这是我拥有的所有库的图像:
所以我用你的pom在Eclipse中创建了一个maven项目。我发现你在两个罐子里得到了org.springframework.core.annotation.AnnotationAwareOrderComparator。 2.5.2弹簧罐和4.0。摆脱2.5.2罐子。那太旧了。新jar与新代码调用的方法具有相同的类。
问题的核心是你加载了核心罐子。
上面的答案(Virmundi)在某种意义上是正确的说两个类是“碰撞”。在我的情况下,我正在定义我的maven依赖很好
<!-- Provided Spring dependencies spring-beans, spring-context, spring-core, spring-tx -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.2.4.RELEASE</version>
</dependency>
但是在我的类路径中有一个旧的Spring jar,其中版本确实没有这个方法
java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotationAwareOrderComparator.sort(Ljava/util/List;)V