2

我正在尝试将我的 Spring MVC 项目移动到 3.2.4。

当我尝试像以前一样使用 Maven 在 IntelliJ 中运行应用程序时,我收到有关无法从 Spring 中找到一系列注释类的错误...

@Bean
@Configuration
@ComponentScan
@PropertySource

都因无法解决类错误消息而失败。

其他注解还可以,这让我觉得是依赖问题,因为 Spring 版本是我项目代码库中的主要变化。

Spring 3.2.4 是否改变了这些注释在包装中的位置?

我当前的 pom(为简洁起见删除了一些位):

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"    
    <!-- SNIP project naming etc, nothing changed from before moving to 3.2.4 -->

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>1.7</java.version>
    <spring.version>3.2.4.RELEASE</spring.version><!-- 3.2.4 -->
    <spring.security.version>3.2.0.RC1</spring.security.version>
</properties>


<dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${spring.version}</version>
    </dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
<version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-expression</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
        <version>${spring.security.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
        <version>${spring.security.version}</version>
    </dependency>


    <dependency><!-- needed for freemarker FreeMarkerConfigurer stuff -->
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>${spring.version}</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-orm</artifactId>
    <version>${spring.version}</version>
    <type>jar</type>
</dependency>


    <!-- LOGGING -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>3.0.0.RELEASE</version>
        <scope>runtime</scope>
        <exclusions>
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jcl-over-slf4j</artifactId>
        <version>1.5.8</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.5.8</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.5.8</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.14</version>
        <scope>runtime</scope>
    </dependency>


<!-- Servlet Spec -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.0.1</version>
        <scope>provided</scope>
    </dependency>

    <!-- view -->
    <!-- SNIP sitemesh/freemarker/jsp etc -->


    <!-- DB access -->
    <!-- SNIP hibernate stuff, sql dialect/driver-->


    <!-- Test -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>${spring.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.7</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<repositories>
    <repository>
        <id>bonecp-repo</id>
        <name>BoneCP Repository</name>
        <url>http://jolbox.com/bonecp/downloads/maven</url>
    </repository>
    <!--<repository>-->
        <!--<id>springsource-milestones</id>-->
        <!--<name>SpringSource Milestones Proxy</name>-->
        <!--<url>https://oss.sonatype.org/content/repositories/springsource-milestones-->
        <!--</url>-->
    <!--</repository>-->
    <!--<repository>-->
        <!--<id>jboss-public-repository-group</id>-->
        <!--<name>JBoss Public Repository Group</name>-->
        <!--<url>http://repository.jboss.org/nexus/content/groups/public</url>-->
    <!--</repository>-->
</repositories>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.0.2</version>
            <configuration>
                <source>${java.version}</source>
                <target>${java.version}</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.0</version>
            <configuration>
                <path>/yhj</path>
            </configuration>
        </plugin>
    </plugins>
</build>

4

2 回答 2

3

您的 POM 中有一个重复的依赖项org.springframework:spring-context,这可能会导致类路径冲突。第一个是使用版本的编译依赖3.2.4.RELEASE,第二个是使用版本的运行时依赖3.0.0.RELEASE

我建议你删除第二个,因为它是不必要的,应该被第一个取代。

于 2013-09-01T18:56:19.320 回答
0

Spring 并不详细说明出了什么问题。要对此进行调试,请将带注释的类复制到 .war 项目中并使其在那里工作。很多事情可能接线错误,但 spring 只会说不满意的自动接线。它应该是开箱即用的,所以有些事情没有正确完成。未设置属性,未满足依赖项等。当您在项目中复制它时,您可以简化问题,一旦它在那里工作,移回类,它应该可以正常工作!

于 2015-10-20T18:25:01.510 回答