春季开始引发异常 [英] Spring Starting throws an exception

查看:78
本文介绍了春季开始引发异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在春季构建最简单的应用程序,并且我的单个控制器具有以下代码

I'm trying to build the simplest app in spring and I have the following code for my single controller

    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.引导一切的那个:

Here is the Main.java. The one that boots everything:

  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

Also this is the 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,因此从技术上讲所有库都应该存在.这是引发的错误(我尝试使用Google搜索,但没有出现任何与我所面对的错误接近的错误):

I have updated the maven hence all the libraries technically should be there. Here is the error that gets thrown(I tried googling it but nothing showed up which came any close to what I faced ):

    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标记. 这是我拥有的所有库的图像:

My user_index.html does exist however I don't think the error is in any kind linked with it since it only has a html tag. Here is an image with all the libraries that I have:

推荐答案

因此,我使用您的pom在Eclipse中创建了一个maven项目.我发现您在两个罐子中得到了org.springframework.core.annotation.AnnotationAwareOrderComparator. 2.5.2弹簧罐和4.0.摆脱2.5.2 jar.那是旧的.新的jar与新代码所调用的方法具有相同的类.

So I created a maven project in Eclipse from your pom. What I've found is that you're getting the org.springframework.core.annotation.AnnotationAwareOrderComparator in two jars. The 2.5.2 spring jar and the 4.0. Get rid of the 2.5.2 jar. That's old. The new jar has the same class with the method that the new code is calling.

从根本上讲,问题是您要双重加载核心罐子.

The issue, at the heart, is that you're double loading the core jars.

这篇关于春季开始引发异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆