Question

I'm trying to read in a property file to a spring context in a confluence plugin. I've added to META-INF/spring the following context file:

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

Also to the pom.xml I've added the following dependency:

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

Unfortunately I keep getting the ClassNotFoundException for PropertyPlaceholderConfigurer. As far as I can tell this is an OSGi problem - because the class isn't referenced from code it is not added by OSGi. Here: https://developer.atlassian.com/display/DOCS/ClassNotFoundException I have found that I should add Import-Package to the spring beans package in the atlassian-plugin.xml but adding this:

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

Does not help. Any suggestions?

Was it helpful?

Solution 2

I found the answer to my question. In order to configure OSGI in confluence one should configure the maven plugin:

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

and put the Import-Package declarations there.

OTHER TIPS

The spring version which mentioned above has OSGI bundles? Can you confirm? Because for some spring versions does not have OSGI bundles. In that case, you need convert to bundles yourself. If its not a OSGI bundle. then package wont be exposed and class wont be able to find , hence your getting above error.

Some details about spring OSGI bundles.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top