문제

I'm trying to move my Spring MVC project to 3.2.4.

When I attempt to run up the application in IntelliJ, using Maven as I had done previously, I am getting errors about not being able to find a series of annotation classes from Spring...

@Bean
@Configuration
@ComponentScan
@PropertySource

are all failing with unable to resolve class error messages.

Other annotations are ok, which makes me think it is a dependency issue, as the Spring version is the main change in my project codebase.

Has Spring 3.2.4 changed where those annotations live in the packaging?

My current pom (some bits removed for brevity):

<?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>

도움이 되었습니까?

해결책

There is a duplicate dependency of org.springframework:spring-context in your POM that is probably causing classpath conflicts. The first one is a compile dependency using version 3.2.4.RELEASE, and the second one is a runtime dependency using version 3.0.0.RELEASE.

I suggest you remove the second since it's unnecessary and should be superseded by the first.

다른 팁

Spring is not verbose about what is going wrong. To debug this, copy annotated class into the .war project and make it work there. A lot of thing may be wired wrong but spring will only say unsatisfied auto-wiring. It should work out-of-the-box, so something is not done properly. A property not set, a dependency not met etc. When you copy it in your project you simplify the problem, once it work there, move back the class and it should work fine!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top