【问题标题】:Spring 3 @PropertySource cannot find properties file in Wildfly 8 moduleSpring 3 @PropertySource 在 Wildfly 8 模块中找不到属性文件
【发布时间】:2016-04-20 23:53:58
【问题描述】:

我正在尝试使用 Spring 的 @PropertySource 注释加载属性文件。属性文件存储在 Wildfly 8 模块中。我收到的错误消息是:

class path resource [campaigner.properties] cannot be opened because it does not exist

这是应用程序服务使用的 Java 代码。

@Configuration
@PropertySource("classpath:campaigner.properties")
class ServiceConfigImpl implements ServiceConfig
{
  @Autowired
  private Environment env;

  @Bean(name = "serviceConfig")
  public ServiceConfig getServiceConfig()
  {
    return new ServiceConfigImpl(this.env);
  }
}

这是我的 jboss-deployment-structure.xml,我将它放在我的 .ear 文件的 META-INF 目录中。

<jboss-deployment-structure> 
  <deployment> 
    <dependencies> 
      <module name="com.dr_dee_sw.campaigner" /> 
    </dependencies> 
  </deployment> 
</jboss-deployment-structure>

我还在 META-INF 目录下放了一个 MANIFEST.MF 文件

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.9.4
Created-By: 1.7.0_71-b14 (Oracle Corporation)
Dependencies: com.dr_dee_sw.campaigner

这是我的模块文件,我已经将它放在 WILDFLY_HOME\modules\com\dr_dee_sw\campaigner\main 目录中,以及 campaigner.properties 文件

<module xmlns="urn:jboss:module:1.1" name="com.dr_dee_sw.campaigner">
  <resources> 
    <resource-root path="."/> 
  </resources> 
</module>

我错过了什么?

【问题讨论】:

    标签: java spring wildfly-8


    【解决方案1】:

    这个页面让我找到了答案:https://www.javacodegeeks.com/2012/09/jboss-as-7-classloading-explained.html。我的 jboss-deployment-structure.xml 是错误的。我在 EAR 文件中有一个 EJB-JAR 文件,它需要成为该文件的焦点。所以,我不得不从使用 切换到 ,如下所示。

    <jboss-deployment-structure> 
      <sub-deployment name="campaigner-service.jar">
        <dependencies> 
          <module name="com.dr_dee_sw.campaigner" /> 
        </dependencies> 
      </sub-deployment>
    </jboss-deployment-structure>
    

    【讨论】:

      猜你喜欢
      • 2016-09-02
      • 2019-05-10
      • 1970-01-01
      • 1970-01-01
      • 2014-07-30
      • 2020-05-25
      • 2018-02-15
      • 1970-01-01
      • 2017-10-16
      相关资源
      最近更新 更多