【问题标题】:Reading properties from a file to a spring context in a Confluence plugin在 Confluence 插件中从文件读取属性到 spring 上下文
【发布时间】:2014-06-27 03:23:51
【问题描述】:

我正在尝试将属性文件读入 confluence 插件中的 spring 上下文。我已将以下上下文文件添加到 META-INF/spring:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:atlassian-spring="http://www.atlassian.com/schema/atlassian-spring"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.atlassian.com/schema/atlassian-spring http://www.atlassian.com/schema/atlassian-spring/atlassian.xsd">

    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value="db.properties"/>
    </bean>

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close">
        <property name="url" value="${db.url}" />
        <property name="driverClassName" value="${db.driver}" />
        <property name="username" value="${db.user}" />
        <property name="password" value="${db.password}" />
    </bean></beans>

我还在 pom.xml 中添加了以下依赖项:

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>2.5.6.SEC02</version>
        <scope>provided</scope>
    </dependency>

不幸的是,我不断收到 PropertyPlaceholderConfigurer 的 ClassNotFoundException。 据我所知,这是一个 OSGi 问题——因为该类不是从代码中引用的,它不是由 OSGi 添加的。 在这里:https://developer.atlassian.com/display/DOCS/ClassNotFoundException 我发现我应该在 atlassian-plugin.xml 中的 spring beans 包中添加 Import-Package 但添加:

<bundle-instructions>
        <Import-Package>org.springframework.beans*</Import-Package>
    </bundle-instructions>

没有帮助。 有什么建议吗?

【问题讨论】:

  • 查看您提供的链接和您拥有的链接,您似乎缺少,。我猜它应该是&lt;Import-Package&gt;org.springframework.beans,*&lt;/Import-Package&gt;

标签: spring maven osgi confluence


【解决方案1】:

上面提到的spring版本有OSGI bundles吗?你可否确认?因为对于某些 spring 版本没有 OSGI 包。在这种情况下,您需要自己转换为捆绑包。如果它不是 OSGI 包。那么包将不会被暴露并且类将无法找到,因此您会遇到错误。

关于 Spring OSGI 包的一些细节。

http://ebr.springsource.com/repository/app/

http://www.srikanthugar.in/2014/04/sspring-framework-is-no-longer.html

http://www.srikanthugar.in/2014/04/how-to-convert-spring-beans-artifact-to.html

【讨论】:

    【解决方案2】:

    我找到了我的问题的答案。为了在 Confluence 中配置 OSGI,应该配置 maven 插件:

    <plugin>
        <groupId>com.atlassian.maven.plugins</groupId>
        <artifactId>maven-***-plugin</artifactId> <!-- *** is the name of the application (product) you're using -->
        <version>3.2.3</version>
        <extensions>true</extensions>
        <configuration>
          <productVersion>${product.version}</productVersion>
          <instructions>
            <!-- OSGi instructions go here -->
          </instructions>
        </configuration>
      </plugin>
    

    并将 Import-Package 声明放在那里。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-05-26
      • 1970-01-01
      • 1970-01-01
      • 2016-04-29
      • 1970-01-01
      • 1970-01-01
      • 2016-12-01
      相关资源
      最近更新 更多