问题
I have a question.I am integrating EJB, JAX-RS, CDI, JPA, and data sources. When I integrate these into wildfly-swarm, there are some problems that can not work properly.
yaml.xml:
datasources:
jdbc-drivers:
com.mysql:
driver-class-name: com.mysql.jdbc.Driver
xa-datasource-class-name: com.mysql.jdbc.jdbc2.optional.MysqlXADataSource
driver-module-name: com.mysql
data-sources:
PicketlinkDS:
driver-name: com.mysql
connection-url: jdbc:mysql://localhost:3306/testjpa
user-name: root
password: javacom2
jta : true
use-java-context: true
min-pool-size : 8
max-pool-size : 20
pool-prefill : true
connection-checker-class-name : org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker
background-validation : true
exception-sorter-class-name : org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter
connection-properties : CharacterEncoding/ UTF-8 UseUnicode/true
persistence.xml:
<persistence-unit name="picketlink" transaction-type="JTA">
<jta-data-source>java:jboss/datasources/PicketlinkDS
</jta-data-source>
<!-- 声明是否扫描jar文件中标注了@Enity类加入到上下文.若不扫描,则如下:(可选) -->
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
<property name="hibernate.query.substitutions" value="true=1, false=0" />
<property name="hibernate.dialect.storage_enginet"
value="innodb" />
<!-- JBoss/Wildfly JTA Transaction -->
<property name="hibernate.transaction.jta.platform"
value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform" />
<property name="hibernate.cache.use_query_cache" value="false" />
<property name="hibernate.cache.use_second_level_cache"
value="false" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="false" />
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="hibernate.hbm2ddl.import_files" value="initial_data.sql" />
<property name="hibernate.jdbc.batch_size" value="1000" />
<property name="hibernate.order_inserts" value="true" />
<property name="hibernate.order_updates" value="true" />
<property name="hibernate.connection.characterEncoding"
value="UTF-8" />
<property name="hibernate.current_session_context_class"
value="jta" />
<property name="wildfly.jpa.default-unit" value="true" />
</properties>
</persistence-unit>
main Class:
ClassLoader cl = Main.class.getClassLoader();
URL stageConfig = cl.getResource("project-development.yml");
Swarm swarm = new Swarm().withConfig(stageConfig);
// Create one or more deployments
JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class);
deployment.addAsWebInfResource(new ClassLoaderAsset("META-INF/persistence.xml", Main.class.getClassLoader()), "classes/META-INF/persistence.xml");
// Add resource to deployment
//deployment.addClass(PmsPersonService.class);
deployment.addClass(Person.class);
// deployment.addClass(EntityManagerProvider.class);
deployment.addAsWebInfResource(new ClassLoaderAsset("META-INF/load.sql", Main.class.getClassLoader()), "classes/META-INF/load.sql");
deployment.addResource(RestApplication.class);
deployment.addResource(HelloWorldEndpoint.class);
deployment.addAllDependencies();
swarm.start();
swarm.deploy(deployment);
exception: "WFLYCTL0412: Required services that are not installed:" =>"jboss.naming.context.java.jboss.datasources.PicketlinkDS"],
idea ,Run on how to deal with this exception? Very anxious!!!!!!!!
回答1:
First off I'd suggest removing the custom main() as there's nothing specific you're doing there that can't be achieved with Maven war
packaging.
Secondly, I think your yaml is missing the swarm:
as the first level, and you can also remove the JDBC Driver creation and let WF Swarm do that for you. For that I switched the driver-name
to mysql
, which will work so long as the JDBC driver dependency for MySQL is part of the project.
swarm:
datasources:
data-sources:
PicketlinkDS:
driver-name: mysql
connection-url: jdbc:mysql://localhost:3306/testjpa
user-name: root
password: javacom2
jta: true
use-java-context: true
min-pool-size: 8
max-pool-size: 20
pool-prefill: true
connection-checker-class-name: org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker
background-validation: true
exception-sorter-class-name: org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter
connection-properties: CharacterEncoding/ UTF-8 UseUnicode/true
来源:https://stackoverflow.com/questions/45349519/wildfly-swarm-jpa-dadatasources-yaml-xml