如何使用Hibernate OGM加入MongoDB和Wildfly [英] How to join MongoDB and Wildfly using Hibernate OGM
问题描述
我试图通过JavaEE7(JAX-RS),Hibernate OGM,MongoDB和Wildfly 10来构建REST应用程序。我试图引用这篇教程。 这里你也可以找到完整的教程源代码。我在当前版本的maven文件中替换了旧版本的依赖关系。目前,当我尝试将应用程序部署到Wildfly时,出现以下错误:
21:20:25,723 ERROR [org.jboss.msc.service.fail](MSC服务线程1-6)MSC000001:无法启动服务jboss.module.service。deployment.RESTApp.war.main:org.jboss.msc.service。服务jboss.module.service中的StartExceptiondeployment.RESTApp.war.main:WFLYSRV0179:无法在org.jboss.as.server.moduleservice.ModuleLoadService中加载module:deployment.RESTApp.war:main
。 start(ModuleLoadService.java:91)
at org.jboss.msc.service.ServiceControllerImpl $ StartTask.startService(ServiceControllerImpl.java:1948)
at org.jboss.msc.service.ServiceControllerImpl $ StartTask。运行(ServiceControllerImpl.java:1881)
位于java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)$ b $位于java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java: 617)
在java.lang.Thread.run(Thread.java:745)
>
>原因:org.jboss.modules.ModuleNotFoundException:org.hibernate:ogm
位于org.jboss.modules.Module.addPaths(Module.java:1092)
位于org.jboss.modules.Module。 (Module.java:1448)
at org.jboss.modules.Module.relinkIfNecessary(Module.java:1476)
at org.jboss.modules.ModuleLoader.loadModule(ModuleLoader.java:225)
at org.jboss.as.server.moduleservice.ModuleLoadService.start(ModuleLoadService.java:68)
... 5 more
和
21:20:32,849错误[org.jboss.as WFLYCTL0013:操作(部署)失败 - 地址:([(deployment=>RESTApp.war))) - 失败描述:{WFLYCTL0080:Failed服务=> {jboss.module.service.\deployment.RESTApp.war \.main=> org.jboss.msc.service.StartException in service jboss.module.service.\deployment.RESTApp.war\.main:WFLYSRV0179:无法加载模块:deployment.RESTApp.war:main
造成者:org.jboss.modules.ModuleNotFoundException:org.hibernate:ogm}}
问题:
: <?xml version =1.0encoding =UTF-8?>
< project xmlns =http://maven.apache.org/POM/4.0.0xmlns:xsi =http://www.w3.org/2001/XMLSchema-instance
xsi:schemaLocation =http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">
< modelVersion> 4.0.0< / modelVersion>
< groupId> RESTApp< / groupId>
< artifactId> RESTApp< / artifactId>
< version> 1.0.0-SNAPSHOT< / version>
<包装>战争< / packaging>
<名称> RESTApp< / name>
<属性>
< project.build.sourceEncoding> UTF-8< /project.build.sourceEncoding>
< project.reporting.outputEncoding> UTF-8< /project.reporting.outputEncoding>
< maven.compiler.source> 1.8< /maven.compiler.source>
< maven.compiler.target> 1.8< /maven.compiler.target>
< version.org.hibernate.ogm> 5.0.3.Final< /version.org.hibernate.ogm>
< version.org.wildfly> 10.1.0.Final< /version.org.wildfly>
< version.org.jboss.arquillian> 1.1.11.Final< /version.org.jboss.arquillian>
< version.org.wildfly.arquillian> 2.0.0.Final< /version.org.wildfly.arquillian>
< jboss.home> C:\MySpace\WildFly\Wildfly_10\WILDFLY_HOME< /jboss.home>
< ogm.module.path> C:\MySpace\Eclipse\eclipseEE\workspace\RESTApp\target\hibernate-ogm-modules< /ogm.module.path>
< / properties>
< dependencyManagement>
<依赖关系>
< dependency>
< groupId> org.hibernate.ogm< / groupId>
< artifactId> hibernate-ogm-core< / artifactId>
< type> pom< / type>
< version> $ {version.org.hibernate.ogm}< / version>
< scope> import< / scope>
< /依赖关系>
< dependency>
< groupId> org.jboss.arquillian< / groupId>
< artifactId> arquillian-bom< / artifactId>
< version> $ {version.org.jboss.arquillian}< / version>
< type> pom< / type>
< scope> import< / scope>
< /依赖关系>
< /依赖关系>
< / dependencyManagement>
< build>
< testResources>
< testResource>
<目录> src / test / java< / directory>
<过滤>真实< /过滤>
< / testResource>
< / testResources>
< pluginManagement>
< plugins>
<! -
可用于运行应用程序进行手动测试,例如通过卷曲;
运行mvn pre-integration-test一次来准备服务器和模块,然后服务器可以通过mvn wildfly:run启动
- >
< plugin>
< groupId> org.wildfly.plugins< / groupId>
< artifactId> wildfly-maven-plugin< / artifactId>
< version> 1.1.0.Beta1< / version>
<配置>
< jboss-home> $ {jboss.home}< / jboss-home>
< modules-path> $ {ogm.module.path}< / modules-path>
<! -
< javaOpts>
< javaOpt> -Xdebug< / javaOpt>
< javaOpt> -Xrunjdwp:transport = dt_socket,server = y,suspend = n,address = 5000< / javaOpt>
< / javaOpts>
- >
< / configuration>
< / plugin>
< plugin>
< groupId> org.apache.maven.plugins< / groupId>
< artifactId> maven-war-plugin< / artifactId>
< version> 3.0.0< / version>
<配置>
< failOnMissingWebXml> false< / failOnMissingWebXml>
< / configuration>
< / plugin>
< / plugins>
< / pluginManagement>
< plugins>
< plugin>
< artifactId> maven-dependency-plugin< / artifactId>
<执行次数>
<执行>
< id>解包< / id>
<阶段>预积分测试< /阶段>
<目标>
< goal>解包< / goal>
< /目标>
<配置>
< artifactItems>
< artifactItem>
< groupId> org.wildfly< / groupId>
< artifactId> wildfly-dist< / artifactId>
< version> $ {version.org.wildfly}< / version>
< type> zip< / type>
< overWrite> false< / overWrite>
< outputDirectory> $ {project.build.directory}< / outputDirectory>
< / artifactItem>
< artifactItem>
< groupId> org.hibernate.ogm< / groupId>
< artifactId> hibernate-ogm-modules-wildfly10< / artifactId>
< version> $ {version.org.hibernate.ogm}< / version>
< type> zip< / type>
< overWrite> false< / overWrite>
< outputDirectory> $ {ogm.module.path}< / outputDirectory>
< / artifactItem>
< / artifactItems>
< / configuration>
< /执行>
< /执行次数>
< / plugin>
< plugin>
< groupId> org.apache.maven.plugins< / groupId>
< artifactId> maven-failsafe-plugin< / artifactId>
< version> 2.19.1< / version>
<执行次数>
<执行>
<目标>
< goal> integration-test< / goal>
<目标>验证< /目标>
< /目标>
< /执行>
< /执行次数>
< / plugin>
< / plugins>
< / build>
<依赖关系>
< dependency>
< groupId> javax< / groupId>
< artifactId> javaee-api< / artifactId>
< version> 7.0< / version>
< scope>提供< / scope>
< /依赖关系>
<! - < artifactId> hibernate-ogm-infinispan< / artifactId> - >
< dependency>
< groupId> org.hibernate.ogm< / groupId>
< artifactId> hibernate-ogm-mongodb< / artifactId>
< scope>提供< / scope>
< /依赖关系>
<! - - 只有在编译时才需要生成映射器实现 - >
< dependency>
< groupId> org.mapstruct< / groupId>
< artifactId> mapstruct-jdk8< / artifactId>
< version> 1.1.0.Final< / version>
< scope>提供< / scope>
< /依赖关系>
< dependency>
< groupId> org.mapstruct< / groupId>
< artifactId>图结构处理器< / artifactId>
< version> 1.1.0.Final< / version>
< scope>提供< / scope>
< /依赖关系>
<! - - 测试 - >
< dependency>
< groupId> junit< / groupId>
< artifactId> junit< / artifactId>
< version> 4.12< / version>
< scope> test< / scope>
< /依赖关系>
< dependency>
< groupId> org.skyscreamer< / groupId>
< artifactId> jsonassert< / artifactId>
< version> 1.4.0< / version>
< scope> test< / scope>
< /依赖关系>
< dependency>
< groupId> org.jboss.arquillian.junit< / groupId>
< artifactId> arquillian-junit-container< / artifactId>
< scope> test< / scope>
< /依赖关系>
< dependency>
< groupId> org.wildfly.arquillian< / groupId>
< artifactId> wildfly-arquillian-container-managed< / artifactId>
< version> $ {version.org.wildfly.arquillian}< / version>
< scope> test< / scope>
<排除项>
<! - 需要这种排除才能在Windows中设置项目:
它包含传递依赖项到JDK JConsole - >
<排除>
< artifactId> wildfly-patching< / artifactId>
< groupId> org.wildfly< / groupId>
< /排除>
< /排除>
< /依赖关系>
< dependency>
< groupId> org.jboss.arquillian.extension< / groupId>
< artifactId> arquillian-rest-client-api< / artifactId>
< version> 1.0.0.Alpha4< / version>
< scope> test< / scope>
< /依赖关系>
< dependency>
< groupId> org.jboss.arquillian.extension< / groupId>
< artifactId> arquillian-rest-client-impl-3x< / artifactId>
< version> 1.0.0.Alpha4< / version>
< scope> test< / scope>
< /依赖关系>
< /依赖关系>
< / project>
<?xml version =1.0encoding =UTF-8?>
< persistence version =2.1
xmlns =http://xmlns.jcp.org/xml/ns/persistencexmlns:xsi =http:// www。 w3.org/2001/XMLSchema-instance
xsi:schemaLocation =
http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp。组织/ XML / NS /持久性/ persistence_2_1.xsd>
< persistence-unit name =primarytransaction-type =JTA>
< provider> org.hibernate.ogm.jpa.HibernateOgmPersistence< / provider>
< class> com.restapp.model.Subscriber< / class>
<属性>
< property name =hibernate.transaction.jta.platformvalue =org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform/>
< property name =hibernate.ogm.datastore.providervalue =mongodb/>
< property name =hibernate.ogm.datastore.databasevalue =db_name/>
< property name =hibernate.ogm.datastore.hostvalue =127.0.0.1/>
< property name =hibernate.ogm.datastore.portvalue =27017/>
< property name =hibernate.ogm.datastore.usernamevalue =robert/>
< property name =hibernate.ogm.datastore.passwordvalue =pwd/>
< / properties>
< / persistence-unit>
< /余辉>
也许 jboss-deployment-structure.xml
文件也很有用:
<?xml version =1.0encoding =UTF-8?> ;
<! -
〜Hibernate OGM,NoSQL数据存储的域模型持久性
〜
〜许可证:GNU较低通用公共许可证(LGPL),版本2.1或更高版本
〜请参阅根目录中的lgpl.txt文件或< http://www.gnu.org/licenses/lgpl-2.1.html> ;.
- >
xmlns =urn:jboss:deployment-structure:1.2
xmlns:xsi =http://www.w3.org/2001/XMLSchema -instance>
< deployment>
<依赖关系>
< module name =org.hibernateslot =ogmservices =import/>
< module name =org.hibernate.ogm.mongodbservices =import/>
< module name =org.hibernate.search.ormservices =import/>
< /依赖关系>
< / deployment>
< / jboss-deployment-structure>
在最新版本中,Hibernate OGM更改了WildFly中的模块,因此您需要更新 jboss-deployment-structure.xml
。
新的位置是:
< module name =org.hibernate.ogmslot =main services =import/>
或者,如果您需要不同的版本系列,则可以选择不同的插槽。例如,对于5.1将是:
< module name =org.hibernate.ogmslot =5.1services =import/>
您需要检查您需要的模块是否存在于WildFly 10模块文件夹中(如果缺少它们,您可以从SourceForge 下载它们)。
编辑:我没有添加模块所在的位置。
$ b Hibernate OGM模块应位于:
$ WILDFLY_HOME / modules / org / hibernate / ogm /
如果他们缺少,只需从模块文件夹中的SourceForge中提取ZIP 。
I'm trying to build the REST application by means of JavaEE7 (JAX-RS), Hibernate OGM, MongoDB and Wildfly 10. I've attempted to refer to THIS tutorial. HERE you can also find the complete source code of the tutorial. I replaced the old version of dependencies in the maven file for the current versions. At the moment, when I try to deploy my application to the Wildfly, I get the following error:
21:20:25,723 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-6) MSC000001: Failed to start service jboss.module.service."deployment.RESTApp.war".main: org.jboss.msc.service.StartException in service jboss.module.service."deployment.RESTApp.war".main: WFLYSRV0179: Failed to load module: deployment.RESTApp.war:main
at org.jboss.as.server.moduleservice.ModuleLoadService.start(ModuleLoadService.java:91)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
>
> Caused by: org.jboss.modules.ModuleNotFoundException: org.hibernate:ogm
at org.jboss.modules.Module.addPaths(Module.java:1092)
at org.jboss.modules.Module.link(Module.java:1448)
at org.jboss.modules.Module.relinkIfNecessary(Module.java:1476)
at org.jboss.modules.ModuleLoader.loadModule(ModuleLoader.java:225)
at org.jboss.as.server.moduleservice.ModuleLoadService.start(ModuleLoadService.java:68)
... 5 more
and
21:20:32,849 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "RESTApp.war")]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.module.service.\"deployment.RESTApp.war\".main" => "org.jboss.msc.service.StartException in service jboss.module.service.\"deployment.RESTApp.war\".main: WFLYSRV0179: Failed to load module: deployment.RESTApp.war:main
Caused by: org.jboss.modules.ModuleNotFoundException: org.hibernate:ogm"}}
Question: How can I fix this issue?
Below you can find pom.xml
file:
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>RESTApp</groupId>
<artifactId>RESTApp</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>RESTApp</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<version.org.hibernate.ogm>5.0.3.Final</version.org.hibernate.ogm>
<version.org.wildfly>10.1.0.Final</version.org.wildfly>
<version.org.jboss.arquillian>1.1.11.Final</version.org.jboss.arquillian>
<version.org.wildfly.arquillian>2.0.0.Final</version.org.wildfly.arquillian>
<jboss.home>C:\MySpace\WildFly\Wildfly_10\WILDFLY_HOME</jboss.home>
<ogm.module.path>C:\MySpace\Eclipse\eclipseEE\workspace\RESTApp\target\hibernate-ogm-modules</ogm.module.path>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.hibernate.ogm</groupId>
<artifactId>hibernate-ogm-core</artifactId>
<type>pom</type>
<version>${version.org.hibernate.ogm}</version>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>${version.org.jboss.arquillian}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<testResources>
<testResource>
<directory>src/test/java</directory>
<filtering>true</filtering>
</testResource>
</testResources>
<pluginManagement>
<plugins>
<!--
May be used to run the application for manual testing, e.g. via curl;
Run "mvn pre-integration-test" once to prepare the server and modules, then the server can be
started via "mvn wildfly:run"
-->
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>1.1.0.Beta1</version>
<configuration>
<jboss-home>${jboss.home}</jboss-home>
<modules-path>${ogm.module.path}</modules-path>
<!--
<javaOpts>
<javaOpt>-Xdebug</javaOpt>
<javaOpt>-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5000</javaOpt>
</javaOpts>
-->
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>pre-integration-test</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-dist</artifactId>
<version>${version.org.wildfly}</version>
<type>zip</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}</outputDirectory>
</artifactItem>
<artifactItem>
<groupId>org.hibernate.ogm</groupId>
<artifactId>hibernate-ogm-modules-wildfly10</artifactId>
<version>${version.org.hibernate.ogm}</version>
<type>zip</type>
<overWrite>false</overWrite>
<outputDirectory>${ogm.module.path}</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<!-- <artifactId>hibernate-ogm-infinispan</artifactId> -->
<dependency>
<groupId>org.hibernate.ogm</groupId>
<artifactId>hibernate-ogm-mongodb</artifactId>
<scope>provided</scope>
</dependency>
<!-- Only needed at build time for generating a mapper implementation -->
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-jdk8</artifactId>
<version>1.1.0.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.1.0.Final</version>
<scope>provided</scope>
</dependency>
<!-- Testing -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.skyscreamer</groupId>
<artifactId>jsonassert</artifactId>
<version>1.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wildfly.arquillian</groupId>
<artifactId>wildfly-arquillian-container-managed</artifactId>
<version>${version.org.wildfly.arquillian}</version>
<scope>test</scope>
<exclusions>
<!-- This exclusion is needed to be able to setup the project in Windows:
it otherwise includes transitive dependency to the JDK JConsole -->
<exclusion>
<artifactId>wildfly-patching</artifactId>
<groupId>org.wildfly</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.extension</groupId>
<artifactId>arquillian-rest-client-api</artifactId>
<version>1.0.0.Alpha4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.extension</groupId>
<artifactId>arquillian-rest-client-impl-3x</artifactId>
<version>1.0.0.Alpha4</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
The persistence.xml
file looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="primary" transaction-type="JTA">
<provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider>
<class>com.restapp.model.Subscriber</class>
<properties>
<property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform" />
<property name="hibernate.ogm.datastore.provider" value="mongodb" />
<property name="hibernate.ogm.datastore.database" value="db_name" />
<property name="hibernate.ogm.datastore.host" value="127.0.0.1" />
<property name="hibernate.ogm.datastore.port" value="27017" />
<property name="hibernate.ogm.datastore.username" value="robert" />
<property name="hibernate.ogm.datastore.password" value="pwd" />
</properties>
</persistence-unit>
</persistence>
Maybe the jboss-deployment-structure.xml
file will be useful as well:
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Hibernate OGM, Domain model persistence for NoSQL datastores
~
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
-->
<jboss-deployment-structure
xmlns="urn:jboss:deployment-structure:1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<deployment>
<dependencies>
<module name="org.hibernate" slot="ogm" services="import" />
<module name="org.hibernate.ogm.mongodb" services="import" />
<module name="org.hibernate.search.orm" services="import" />
</dependencies>
</deployment>
</jboss-deployment-structure>
In the latest versions, Hibernate OGM changed the name of the moduel in WildFly, so you need to update your jboss-deployment-structure.xml
.
The new location is:
<module name="org.hibernate.ogm" slot="main" services="import" />
Or, if you need a different version family you can select a different slot. For example, for 5.1 will be:
<module name="org.hibernate.ogm" slot="5.1" services="import" />
You need to check that the module you need is present in the WildFly 10 modules folder (you can download them from SourceForge if they are missing).
EDIT: I didn't add where the modules are located.
Hibernate OGM modules should be located under:
$WILDFLY_HOME/modules/org/hibernate/ogm/
If they are missing just extract the ZIP from SourceForge in the modules folder.
这篇关于如何使用Hibernate OGM加入MongoDB和Wildfly的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!