Okay, I moved to trying to do this with a blueprint rather than doing this via spring configurations. It is really disappointing how long it takes to configure something that I expect to take no more than an hour (it has taken me well over 40 hours between pouring through documentation and trying different combinations). Here is where I am at.
First, I have a blueprint that defines the datasource I am using:
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<bean id="myDSBean" class="net.sourceforge.jtds.jdbcx.JtdsDataSource">
<property name="databaseName" value="test" />
<property name="password" value="password" />
<property name="portNumber" value="1433" />
<property name="serverName" value="10.10.10.10" />
<property name="user" value="sa" />
</bean>
<service interface="javax.sql.DataSource" ref="myDSBean">
<service-properties>
<entry key="osgi.jndi.service.name" value="MyDS"/>
</service-properties>
</service>
</blueprint>
I am able to deploy this and it starts up fine.
Next, I have my bundle. The bundle has the following files:
/src/main/resources/jpa/EachEntity.xml
These contain the entity mappings. These worked fine with a Spring configuration. Here is an example:
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings
xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd"
version="2.0">
<package>com.mycompany.data.entity</package>
<entity class="MyEntity" metadata-complete="false" />
</entity-mappings>
/src/main/resources/META-INF/persistence.xml
Here is a snippet:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="persistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<non-jta-data-source>osgi:services/javax.sql.DataSource/(osgi.jndi.service.name=MyDS)</non-jta-data-source>
<mapping-file>jpa/MyEntity.xml</mapping-file>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect" />
<property name="hibernate.default_schema" value="dbo" />
</properties>
</persistence-unit>
</persistence>
/src/main/resources/OSGI-INF/blueprint.xml
This is the blueprint for the service that I am exposing.
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/blueprint/jaxws"
xmlns:soap="http://cxf.apache.org/bindings/soap"
xmlns:jpa="http://aries.apache.org/xmlns/jpa/v1.0.0"
xmlns:tx="http://aries.apache.org/xmlns/transactions/v1.0.0"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0
http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://cxf.apache.org/blueprint/jaxws
http://cxf.apache.org/schemas/blueprint/jaxws.xsd
http://cxf.apache.org/blueprint/core
http://cxf.apache.org/schemas/blueprint/core.xsd">
<bean id="myEntityDAO" class="com.mycompany.data.dao.jpa.MyEntityJpaDAO">
<jpa:context property="entityManager" unitname="persistenceUnit" />
</bean>
<jaxws:endpoint
xmlns:nmgr="http://www.mycompany.com/service/MyService/"
id="myService"
address="/MyService"
serviceName="nmgr:MyService"
endpointName="nmgr:MyServiceSOAP"
implementor="#myServiceImpl"/>
<bean id="myServiceImpl"
class="com.mycompany.service.myservice.impl.MyServiceImpl">
<property name="myEntityDAO" ref="myEntityDAO" />
</bean>
</blueprint>
pom.xml
My felix configuration:
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Export-Package>!com.mycompany.schemas.*</Export-Package>
<Private-Package>
com.mycompany.*
</Private-Package>
<Import-Package>
javassist.util.proxy,
javax.sql,
javax.persistence.spi,
javax.persistence.metamodel,
javax.persistence.criteria,
org.hibernate;version=${hibernate.version},
org.hibernate.proxy;version=${hibernate.version},
org.hibernate.ejb;version=${hibernate.version},
org.springframework.aop;version=${spring.version},
org.springframework.aop.framework;version=${spring.version},
org.aopalliance.aop,
javax.naming.*,
*
</Import-Package>
<Meta-Persistence>META-INF/persistence.xml</Meta-Persistence>
</instructions>
</configuration>
Result
First, the blueprint of the service has errors for <jpa:context /> and <jpa:unit />
cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'jpa:context'.
Second, when the bundle is deployed, there is no web service and the only log I see is:
2012-04-18 20:50:36,642 | WARN | l Console Thread | container | ? ? | 170 - org.apache.aries.jpa.container - 0.3.0 | There are no providers available.
Doesnt look like any of the beans are initialized from the blueprint.xml.
Also, I am looking for opinions / information / options on the following:
1) Can I use spring's component scanning mechanism in a blueprint? I was not sure if I was forced to use <jpa:context /> and <jpa:unit />.
2) Looking at the documentation for aries, it also looks like the transactions schema forces me to define transactions at the DAO level. Is this true?
3) Can I refer to blueprint.xml beans from the spring configured beans?
Again, your help is appreciated. I really want to feel comfortable with and be an advocate for this product.