Why can't Maven build resolve Spring @Bean @Configuration etc annotations?

DaFoot

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>

superEb

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why can't Maven build resolve @Override annotations?

From Dev

Spring @Configuration file with PropertyPlaceholderConfigurer bean doesn't resolve @Value annotation

From Dev

Why spring can't find my bean?

From Dev

Why spring can't find my bean?

From Dev

Why can't activator resolve a custom dependency in local maven repository?

From Dev

Spring MVC + Hibernate + Maven : Multiple annotations found in bean declaration

From Dev

Why I can't inject a Spring Environment object into my bean?

From Dev

Maven Build - Couldn't resolve dependencies

From Dev

Why can't Google Chrome resolve subdomains from /private/etc/hosts?

From Dev

Why can't it resolve the method?

From Dev

Can't get Spring bean

From Dev

Why Spring Boot is not finding a @Service bean trying to perform autowiring? the bean exist but it can't find it

From Java

If Spring can successfully intercept intra class function calls in a @Configuration class, why does it not support it in a regular bean?

From Dev

If Spring can successfully intercept intra class function calls in a @Configuration class, why does it not support it in a regular bean?

From Dev

Why can't I build Spring Data Commons?

From Dev

Spring : annotations for @Configuration class

From Dev

Can the maven reactor resolve module dependencies locally when resuming a build?

From Dev

Multiple Configurations of a Bean with Spring Annotations

From Dev

Maven can't resolve the Kotlin Maven Plugin jar

From Dev

Why can't a set a mockito mock to a field of a autowired initialized spring bean?

From Dev

Why can't chef resolve my cookbooks?

From Dev

Why can't apt resolve names?

From Dev

Why can't Gradle resolve some dependencies?

From Dev

Why do I not need @Autowired on @Bean methods in a Spring configuration class?

From Dev

Can't instantiate Spring bean repository

From Dev

Why can't my jar files and my .war file be found within my project build? Maven

From Dev

Spring Annotations: Why @Required doesn't work when class is @Autowired

From Dev

Spring Annotations: Why @Required doesn't work when class is @Autowired

From Dev

Why shouldn't I mix Spring and Java annotations?

Related Related

  1. 1

    Why can't Maven build resolve @Override annotations?

  2. 2

    Spring @Configuration file with PropertyPlaceholderConfigurer bean doesn't resolve @Value annotation

  3. 3

    Why spring can't find my bean?

  4. 4

    Why spring can't find my bean?

  5. 5

    Why can't activator resolve a custom dependency in local maven repository?

  6. 6

    Spring MVC + Hibernate + Maven : Multiple annotations found in bean declaration

  7. 7

    Why I can't inject a Spring Environment object into my bean?

  8. 8

    Maven Build - Couldn't resolve dependencies

  9. 9

    Why can't Google Chrome resolve subdomains from /private/etc/hosts?

  10. 10

    Why can't it resolve the method?

  11. 11

    Can't get Spring bean

  12. 12

    Why Spring Boot is not finding a @Service bean trying to perform autowiring? the bean exist but it can't find it

  13. 13

    If Spring can successfully intercept intra class function calls in a @Configuration class, why does it not support it in a regular bean?

  14. 14

    If Spring can successfully intercept intra class function calls in a @Configuration class, why does it not support it in a regular bean?

  15. 15

    Why can't I build Spring Data Commons?

  16. 16

    Spring : annotations for @Configuration class

  17. 17

    Can the maven reactor resolve module dependencies locally when resuming a build?

  18. 18

    Multiple Configurations of a Bean with Spring Annotations

  19. 19

    Maven can't resolve the Kotlin Maven Plugin jar

  20. 20

    Why can't a set a mockito mock to a field of a autowired initialized spring bean?

  21. 21

    Why can't chef resolve my cookbooks?

  22. 22

    Why can't apt resolve names?

  23. 23

    Why can't Gradle resolve some dependencies?

  24. 24

    Why do I not need @Autowired on @Bean methods in a Spring configuration class?

  25. 25

    Can't instantiate Spring bean repository

  26. 26

    Why can't my jar files and my .war file be found within my project build? Maven

  27. 27

    Spring Annotations: Why @Required doesn't work when class is @Autowired

  28. 28

    Spring Annotations: Why @Required doesn't work when class is @Autowired

  29. 29

    Why shouldn't I mix Spring and Java annotations?

HotTag

Archive