1

I have confluence plugin project and I want to implement transactions for my service classes using spring annotations, but I get the error:

[INFO] [talledLocalContainer]2014-05-23 13:12:06,298 ERROR [main][plugin.osgi.factory.OsgiPlugin] enableInternal Detected an error (BundleException) enabling the plugin 'mypackage'
: Unresolved constraint in bundle mypackage [176]: Unable to resolve 176.0: missing  requirement [176.0] package; (&(package=org.springframework.jdbc.datasource.DataSour
ceTransactionManager)(version>=2.5.6.SEC02)).  This error usually occurs when your      plugin imports a package from another bundle with a specific versio
n constraint and either the bundle providing that package doesn't meet those version   constraints, or there is no bundle available that provides the specified package.
For more details on how to fix this, see https://developer.atlassian.com/x/mQAN

Here is the code:

myconfigfile.xml

...
<!-- TRANSACTIONS CONF -->
    <!-- enable the configuration of transactional behavior based on annotations -->
    <tx:annotation-driven transaction-manager="txManager"/>

    <!-- PlatformTransactionManager -->
    <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>
<!-- TRANSACTIONS CONF END-->

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

<bean id="transactionAwareDataSource"
    class="org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy">
    <constructor-arg ref="dataSource" />
</bean>

<bean id="connectionProvider" class="org.jooq.impl.DataSourceConnectionProvider">
    <constructor-arg ref="transactionAwareDataSource" />
</bean>
...

service.class

@Service
@Transactional
public class AdminServiceImpl implements AdminService<ProjectRecord> {

private IDao<ProjectRecord> dao;

@Autowired
public AdminServiceImpl(IDao<ProjectRecord> dao) {
    super();
    this.dao = dao;
    // TODO Auto-generated constructor stub
}

@Override
public void delete(Long id) {
    // TODO Auto-generated method stub
    dao.delete(id);
}

@Override
public void changeName(Long id, String newName) {
    // TODO Auto-generated method stub
    dao.update(dao.findbyId(id));
}

}

pom.xml

...
<dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>2.5.6.SEC02</version>
        <scope>provided</scope>
</dependency>
...
...
<plugin>
            <groupId>com.atlassian.maven.plugins</groupId>
            <artifactId>maven-confluence-plugin</artifactId>
            <version>${amps.version}</version>
            <extensions>true</extensions>
            <configuration>
                <productVersion>${confluence.version}</productVersion>
                <productDataVersion>${confluence.data.version}</productDataVersion>
                <instructions>
                    <Import-Package>
                        org.springframework.jdbc.datasource.DataSourceTransactionManager;version="2.5.6.SEC02"
                    </Import-Package>
                </instructions>
            </configuration>
        </plugin>
        <plugin>

and in my project in referenced libraries I have apropriate library:

enter image description here

That am I doing wrong?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
user2374573
  • 59
  • 1
  • 3
  • 11

1 Answers1

0

I had a similar problem, unfortunately solving it using the statements did not yield a proper solution. When you add the import-statement you will need to specify ALL of the dependencies your project uses not just ones that you seem to be lacking. It seems specifying the imports will turn off the autogenerated manifest entries. But even after you specify all of the imports you will find out that your spring contexts have stopped being read! I circumvented this problem by deleting the import-package all together and created a class called OsgiImports in which I keep a table of classes I want to have imported by the container. That makes the autogenerated manifest pick up all needed dependencies. I.e. sth like this:

package com.rulefinancial.uservoice;

import org.aopalliance.aop.Advice;
import org.apache.commons.dbcp.BasicDataSource;
import org.springframework.aop.SpringProxy;
import org.springframework.aop.framework.Advised;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy;

public class OsgiImports {
    public Class<?>[] imports = {
            PropertyPlaceholderConfigurer.class,
            BasicDataSource.class,
            DataSourceTransactionManager.class,
            TransactionAwareDataSourceProxy.class,
            SpringProxy.class,
            Advised.class,
            Advice.class
    };

}
norbitheeviljester
  • 952
  • 1
  • 6
  • 17