【问题标题】:Spring WAR doesn't create BuildProperties BeanSpring WAR 不会创建 BuildProperties Bean
【发布时间】:2017-12-13 18:57:40
【问题描述】:

我正在对我的一个项目工件进行一些转换,以便我们可以使用 spring boot 运行它,而不仅仅是部署到 jboss,以及添加执行器。这已经很顺利了,但是在使一切都在 spring boot 上运行的过程中,我破坏了将 WAR 部署到 jboss 的能力。

具体来说,我已将 BuildInformation 添加到我们的部署信息端点。根据我对执行器和 build-info.properties 创建的理解,以及我在试图找到其他有此问题的人时发现的每一个谷歌结果,我目前正在做的事情应该是在职的。我有

    compile 'org.springframework.boot:spring-boot-starter-actuator'

在我的平台级项目的 gradle 的 subprojects 部分(以及我们使用的所有其他 spring-boot 依赖项)。 springBoot 任务配置为运行buildInfo()。生成的 WAR 文件在 /WEB-INF/classes/META-INF/ 下具有 build-info.properties 文件。一切似乎都完全按照应有的方式组合在一起。然而:

13:09:59,517 ERROR [org.springframework.web.servlet.DispatcherServlet] (ServerService Thread Pool -- 53) Context initialization failed: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'pingController' defined in VFS resource ["<snip>/PingController.class"]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.boot.info.BuildProperties' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}

对我应该去哪里有什么想法吗?

【问题讨论】:

    标签: java spring spring-boot gradle spring-boot-actuator


    【解决方案1】:

    尽管带有main 方法的类被@SpringBootApplication 注释,但在打包到WAR 时仍然没有启用自动配置。我在我的根 @Configuration 类上添加了@EnableAutoConfiguration,一切都结束了。

    【讨论】:

    • 除非您还扩展 SpringBootServletInitializer,否则带有 main 的类在 WAR 中不会做任何事情。
    • 我很确定它是
    【解决方案2】:

    如果有人发现这一点,我的问题是,当 IDE 构建代码时,我没有构建属性,但如果我从控制台或 Intellij 中的 maven 工具窗口运行“maven install”,Spring将创建 BuildProperties 构建。我怀疑 IDE 可能会采取一些捷径。例如,构建时间戳停留在最后一个“真实”构建。

    使用 Intellij,通过单击 View > Tools Windows > Maven 来显示 Maven 面板。然后打开生命周期并右键单击您要运行的 maven 目标(最常安装)并运行

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-08
      • 2019-08-31
      • 2018-01-20
      • 2015-05-29
      • 2019-09-08
      • 2016-02-20
      • 2012-06-04
      • 2017-04-17
      相关资源
      最近更新 更多