从Spring Boot 1.2.8切换到1.3.2后,应用程序神奇地停止工作

时间:2016-02-09 20:34:03

标签: spring-boot

从Spring Boot 1.2.8升级到1.3.2后,我的应用程序突然停止工作。

应用程序启动后,我得到以下异常。

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.context.support.ResourceBundleMessageSource] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1373)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1119)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545)
    ... 25 more

看起来ResourceBundleMessageSource存在问题,但我不知道为什么。在版本1.2.8中,一切都像魅力一样。

这是我的pom.xml

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

    <!--replace with your namespace and version -->
    <groupId>my</groupId>
    <artifactId>project</artifactId>
    <version>0.1</version>

    <properties>
        <hibernate.version>5.0.2.Final</hibernate.version>
        <spring.data.jpa.version>1.9.0.RELEASE</spring.data.jpa.version>
        <spring.social.version>1.1.2.RELEASE</spring.social.version>
        <spring.social.twitter.version>1.1.1.RELEASE</spring.social.twitter.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <start-class>my.project.Application</start-class>
        <java.version>1.8</java.version>
    </properties>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.2.RELEASE</version>
        <relativePath />
    </parent>

    <repositories>
        <repository>
            <id>project.local</id>
            <name>my-project</name>
            <url>file:${project.basedir}/repo</url>
        </repository>
    </repositories>


    <build>
    <plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.3</version>
        <configuration>
            <compilerArgs>
                <arg>-parameters</arg>
            </compilerArgs>
            <source>1.8</source>
            <target>1.8</target>
        </configuration>
    </plugin>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
    </plugins>
  </build>

  <dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.thymeleaf.extras</groupId>
        <artifactId>thymeleaf-extras-springsecurity4</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>     
        <groupId>org.springframework.social</groupId>
        <artifactId>spring-social-security</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-social-facebook</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.social</groupId>
        <artifactId>spring-social-google</artifactId>
        <version>1.0.0.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.4-1203-jdbc42</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-java8</artifactId>
        <version>${hibernate.version}</version>
    </dependency>   
    <dependency>
        <groupId>joda-time</groupId>
        <artifactId>joda-time</artifactId>
        <version>2.8.2</version>
    </dependency>
    <dependency>
        <groupId>org.jadira.usertype</groupId>
        <artifactId>usertype.jodatime</artifactId>
        <version>2.0.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.4</version>
    </dependency>
    <dependency>
        <groupId>net.tanesha.recaptcha4j</groupId>
        <artifactId>recaptcha4j</artifactId>
        <version>0.0.7</version>
    </dependency>
    <dependency>
        <groupId>javax.json</groupId>
        <artifactId>javax.json-api</artifactId>
        <version>1.0</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish</groupId>
        <artifactId>javax.json</artifactId>
        <version>1.0.4</version>
    </dependency>
    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>javax.mail-api</artifactId>
        <version>1.5.4</version>
    </dependency>
    <dependency>
        <groupId>com.sun.mail</groupId>
        <artifactId>javax.mail</artifactId>
        <version>1.5.4</version>
    </dependency>
  </dependencies>
</project>

2 个答案:

答案 0 :(得分:2)

听起来您有一个或多个messages_${locale}.properties个文件,但没有messages.properties个文件。来自1.3.2 release announcement

  

如果您从1.3.1升级,则有一个潜在的突破性变化;我们现在只搜索messages.properties(而不是messages*.properties)以启用消息源的自动配置。如果您之前有一个messages_en.properties格式的消息文件而您没有包含默认的messages.properties文件,那么现在需要添加一个。

答案 1 :(得分:-2)

@Jagger,@ XtremeBiker点有效使用父依赖项,而这些依赖项又将包含所有必需的库本身。你最终得到了干净的pom文件。你早期版本的spring-boot项目正在运行的原因是你已经具备了所有必需的依赖项,但是在任何连续的SPRING版本中,一些依赖项被删除了,而一些被包含在内,并且很常见。因此很有可能在更新后会破坏任何正常工作的代码。

现在关于上述问题,可以看出项目类路径中缺少ResourceBundleMessageSource,所以请包含最新版本的spring-context&amp;尝试: -

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>4.2.4.RELEASE</version>
</dependency>