我正在尝试使以下代码正常工作,以便我可以从 JPA 实体中使用。
String DATASOURCE_CONTEXT = "java:jboss/datasources/WikiDS";
Connection result = null;
DataSource datasource = null;
try {
Context initialContext = new InitialContext();
datasource = (DataSource)initialContext.lookup(DATASOURCE_CONTEXT);
if (datasource == null) {
System.out.println("Data source is null");
}
else {
System.out.println("Data source is OK!!!");
}
}
catch(NamingException ex) {
System.out.println("Naming exception is: " + ex.getMessage());
}
SimpleRegistry reg = new SimpleRegistry() ;
reg.put("myDataSource",datasource);
CamelContext context = new DefaultCamelContext(reg);
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
context.addComponent("test-jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
context.addRoutes(new RouteBuilder() {
public void configure() {
from("jpa://org.apache.camel.example.jmstofile?consumer.namedQuery=step1&consumeDelete=false").to("file://test");
}
});
ProducerTemplate template = context.createProducerTemplate();
context.start();
无论我做什么,我都会得到以下异常。
[错误] 无法在项目 camel-example-jms-file 上执行目标 org.codehaus.mojo:exec-maven-plugin:1.1.1:java (default-cli):执行 Java 类时发生异常. null:InvocationTargetException:没有名为 camel 的 EntityManager 的持久性提供程序。
有什么解决办法吗?
问候,
肖恩
最佳答案
添加&persistenceUnit=<name-of-your-unit>
到您的 URI,其中 <name-of-your-unit>
是 persistence.xml
中给出的持久性单元的名称.
关于jpa - Camel JPA - 没有名为 camel 的 EntityManager 的持久性提供程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21337796/