尝试示例" Chap7-Recipe3-JPA-Only"从karafCookbook(见https://github.com/jgoodyear/ApacheKarafCookbook)in karaf 3.0.X到4.1.1我得到了以下错误:
Missing dependencies:
(&(objectClass=org.apache.aries.blueprint.NamespaceHandler)(osgi.service.blueprint.namespace=http://aries.apache.org/xmlns/jpa/v1.1.0))
我没有找到需要依赖的地方以及如何修复它。
这是我从fresly安装的karaf 4.0.9输入的命令:
karaf@root()> version
4.0.9
karaf@root()> install -s mvn:org.apache.derby/derbyclient/10.8.1.2
Bundle ID: 52
karaf@root()> feature:install jndi
karaf@root()> feature:install jpa
karaf@root()> install -s mvn:com.packt/jpa-only
JPA-Only Demo Bundle starting...
Bundle ID: 81
karaf@root()> list
START LEVEL 100 , List Threshold: 50
ID | State | Lvl | Version | Name
--------------------------------------------------------------------------------------------
52 | Active | 80 | 10.8.1000002.1095077 | Apache Derby 10.8
60 | Active | 80 | 3.0.0 | Expression Language 3.0 API
61 | Active | 80 | 1.2.0 | CDI APIs
62 | Active | 80 | 1.2 | javax.interceptor API
63 | Active | 80 | 1.2 | javax.transaction API
64 | Active | 80 | 2.6.0 | Apache Aries JPA Container API
65 | Active | 80 | 2.6.0 | Apache Aries JPA blueprint
66 | Active | 80 | 2.6.0 | Apache Aries JPA container
67 | Active | 80 | 2.6.0 | Apache Aries JPA support
68 | Active | 80 | 3.2.2 | Apache Commons Collections
69 | Active | 80 | 2.6 | Commons Lang
70 | Active | 80 | 1.6.0 | Commons Pool
71 | Active | 80 | 1.0.2 | Apache Felix Coordinator Service
72 | Active | 80 | 1.1.1 | geronimo-jms_1.1_spec
73 | Active | 80 | 1.1 | Apache Geronimo JSR-317 JPA 2.0 Spec API
74 | Active | 80 | 2.4.1 | OpenJPA Aggregate Jar
75 | Active | 80 | 1.7.0.6 | Apache ServiceMix :: Bundles :: ant
76 | Active | 80 | 1.4.0.3 | Apache ServiceMix :: Bundles :: commons-dbcp
77 | Active | 80 | 1.0.0.2 | Apache ServiceMix :: Bundles :: javax.inject
78 | Active | 80 | 1.14.1.1 | Apache ServiceMix :: Bundles :: serp
79 | Active | 80 | 4.3.0 | Apache XBean :: ASM 5 shaded (repackaged)
80 | Active | 80 | 1.0.0.201505202023 | org.osgi:org.osgi.service.jdbc
81 | GracePeriod | 80 | 1.0.0.SNAPSHOT | Chapter 7 :: Recipe 3 :: JPA-ONLY - 4.0.9
karaf@root()> diag 81
Chapter 7 :: Recipe 3 :: JPA-ONLY - 4.0.9 (81)
----------------------------------------------
Status: GracePeriod
Blueprint
09/06/17 11:13
Missing dependencies:
(&(objectClass=org.apache.aries.blueprint.NamespaceHandler)(osgi.service.blueprint.namespace=http://aries.apache.org/xmlns/jpa/v1.1.0))
最后,我在pom.xml中修改了libs版本,因此它在4.0.9中加载:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>chapter7-recipe3</artifactId>
<groupId>com.packt</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>jpa-only</artifactId>
<packaging>bundle</packaging>
<name>Chapter 7 :: Recipe 3 :: JPA-ONLY - 4.0.9</name>
<dependencies>
<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.commons-dbcp</artifactId>
<version>1.4_3</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.enterprise</artifactId>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jpa_2.0_spec</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa</artifactId>
<version>2.4.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.8.1.2</version>
<scope>provided</scope>
</dependency>
<!-- custom felix gogo command -->
<dependency>
<groupId>org.apache.karaf.shell</groupId>
<artifactId>org.apache.karaf.shell.console</artifactId>
<version>4.0.9</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>openjpa-maven-plugin</artifactId>
<configuration>
<addDefaultConstructor>true</addDefaultConstructor>
<enforcePropertyRestriction>true</enforcePropertyRestriction>
</configuration>
<executions>
<execution>
<id>enhancer</id>
<phase>process-classes</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa</artifactId>
<version>2.4.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.6</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>3.3.0</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Meta-Persistence>META-INF/persistence.xml</Meta-Persistence>
<Bundle-Activator>com.packt.jpa.demo.Activator</Bundle-Activator>
<Export-Package>
com.packt.jpa.demo.api.*
</Export-Package>
<Import-Package>
org.osgi.service.blueprint;resolution:=optional,
javax.persistence;version="[1.1,2)",
javax.persistence.criteria;version="[1.1,2)",
javax.sql,
org.apache.commons.dbcp;version="[1.4,2)",
org.apache.derby.jdbc,
org.apache.felix.service.command,
org.apache.felix.gogo.commands,
org.apache.karaf.shell.console,
*
</Import-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>maven2-repository.dev.java.net</id>
<name>Java.net Repository for Maven</name>
<url>http://download.java.net/maven/2/</url>
<layout>default</layout>
</repository>
</repositories>
</project>
blueprint.xml保持不变,如下所示:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<blueprint default-activation="eager"
xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://aries.apache.org/xmlns/transactions/v1.0.0"
xmlns:jpa="http://aries.apache.org/xmlns/jpa/v1.1.0">
<!-- Define RecipeBookService Services, and expose them. -->
<bean id="recipeBookService" class="com.packt.jpa.demo.dao.RecipeBookServiceDAOImpl">
<jpa:unit property="entityManagerFactory" unitname="recipe" />
</bean>
<service ref="recipeBookService" interface="com.packt.jpa.demo.api.RecipeBookService" />
<!-- Standard DataSource -->
<bean id="dataSource" class="org.apache.derby.jdbc.ClientDataSource" >
<property name="databaseName" value="demo"/>
<property name="createDatabase" value="create"/>
</bean>
<service id="demoDataSource" ref="dataSource" interface="javax.sql.DataSource">
<service-properties>
<entry key="osgi.jndi.service.name" value="jdbc/demo"/>
<entry key="transactional" value="false"/>
</service-properties>
</service>
<!-- Apache Karaf Commands -->
<command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
<command>
<action class="com.packt.jpa.demo.commands.AddRecipe">
<property name="recipeBookService" ref="recipeBookService"/>
</action>
</command>
<command>
<action class="com.packt.jpa.demo.commands.RemoveRecipe">
<property name="recipeBookService" ref="recipeBookService"/>
</action>
</command>
<command>
<action class="com.packt.jpa.demo.commands.ListRecipes">
<property name="recipeBookService" ref="recipeBookService"/>
</action>
</command>
</command-bundle>
</blueprint>
有什么想法吗? 感谢。