通过JBoss 7.1部署EJB [英] deploying EJB over JBoss 7.1
问题描述
警告:-logmodule已被弃用。请使用系统属性java.util.logging.manager或java.util.logging.LogManager服务加载器。
13:15:54,638 INFO [org.jboss.modules] JBoss模块1.1.1.GA
13:15:55,094 INFO [org.jboss.msc] JBoss MSC版本1.0.2.GA
13:15:55,175 INFO [org.jboss.as] JBAS015899:JBoss AS 7.1.0.FinalThunder起始
13:15:56,587 INFO [org.xnio] XNIO版本3.0.3 .GA
13:15:56,592 INFO [org.jboss.as.server] JBAS015888:使用套接字绑定(management-http)创建http管理服务
13:15:56,602 INFO [org.xnio .nio] XNIO NIO实现版本3.0.3.GA
13:15:56,614 INFO [org.jboss.remoting] JBoss Remoting版本3.2.2.GA
13:15:56,655 INFO [org。 jboss.as.logging] JBAS011502:删除引导日志处理程序
13:15:56,661 INFO [org.jboss.as.configadmin](ServerService线程池 - 26)JBAS016200:激活ConfigAdmin子系统
13: 15:56,707 INFO [org.jboss.as.clustering.infinispan](ServerService线程池 - 31)JBAS010280:激活Infinispan子系统。
13:15:56,793 INFO [org.jboss.as.connector](MSC服务线1-3)JBAS010408:启动JCA子系统(JBoss IronJacamar 1.0.7.Final)
13:15:56,822 INFO [org.jboss.as.naming](ServerService线程池 - 38)JBAS011800:激活命名子系统
13:15:56,839 INFO [org.jboss.as.osgi](ServerService Thread Pool - 39) JBAS011940:激活OSGi子系统
13:15:56,881 INFO [org.jboss.as.security](ServerService线程池 - 44)JBAS013101:激活安全子系统
13:15:56,889 INFO [org。 jboss.as.naming](MSC服务线程1-1)JBAS011802:启动命名服务
13:15:56,898 INFO [org.jboss.as.mail.extension](MSC服务线程1-2)JBAS015400:绑定邮件会话[java:jboss / mail /默认]
13:15:56,933 INFO [org.jboss.as.security](MSC服务线程1-2)JBAS013100:当前PicketBox版本= 4.0.6.final
13:15:56,989 INFO [org.jboss.as.webservices](ServerService线程池 - 48)JBAS015537:激活WebServices扩展
13:15:57,324 INFO [org.jboss.ws.common.management.AbstractServerConfig](MSC服务线程1-2)JBoss Web Services - Stack CXF Server 4.0.1.GA
13:15:57,501 INFO http:// localhost? server.deployment.scanner](MSC服务线程1-2)JBAS015012:启动FileSystemDeploymentService目录/usr/bin/jboss-as-7.1.0.Final/standalone/deployments
13:15:58,265 INFO [org .jboss.as.remoting](MSC服务线程1-1)JBAS017100:收听/127.0.0.1:4447
13:15:58,265 INFO [org.jboss.as.remoting](MSC服务线程1- 3)JBAS017100:听/127.0.0.1:9999
13:15:58,272 INFO [org.jboss.as.server.deployment.scanner](DeploymentScanner-threads - 1)JBAS015003:在部署中找到HelloWorld.war目录。触发部署创建一个名为HelloWorld.war.dodeploy的文件
13:15:58,581 INFO [org.jboss.as.controller](控制器引导线程)JBAS014774:服务状态报告
JBAS014775:新的缺失/不满足依赖:
服务jboss.jdbc-driver.com_mysql(缺少)依赖关系:[service jboss.data-source.java:jboss/datasources/EjbMySql]
13:15:58,589错误[org.jboss.as](控制器启动线程)JBAS015875:JBoss AS 7.1.0.FinalThunder在4548ms中启动(带有错误) - 204个服务中启动131个服务(2个服务失败或缺少依赖关系,70个服务是被动或按需)
看起来我需要在某处添加包含,我的代码很简单。 ..
包服务器;
import java.io.IOException;
import java.io.PrintWriter;
import javax.ejb.EJB;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceUnit;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.MyUser;
/ **
* Servlet实现类HelloServlet
* /
@WebServlet(/ HelloServlet)
public class HelloServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@EJB HelloBean bean;
@PersistenceUnit
EntityManagerFactory emF;
/ **
* @see HttpServlet#HttpServlet()
* /
public HelloServlet(){
super();
// TODO自动生成的构造函数存根
}
/ **
* @see HttpServlet#doGet(HttpServletRequest请求,HttpServletResponse响应)
* /
protected void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException {
PrintWriter out = response.getWriter();
out.print(< html>< body>);
MyUser user =(MyUser)emF.createEntityManager()。createQuery(select * from myuser)getResultList()。get(0);
out.println(Username =+ user.getName());
out.print(< / body>< / html>);
}
/ **
* @see HttpServlet#doPost(HttpServletRequest请求,HttpServletResponse响应)
* /
protected void doPost(HttpServletRequest request, HttpServletResponse响应)throws ServletException,IOException {
// TODO自动生成的方法存根
}
}
Persistance.xml如下所示...
<?xml version =1.0encoding =UTF-8?>
< persistence version =2.0xmlns =http://java.sun.com/xml/ns/persistencexmlns:xsi =http://www.w3.org/2001/XMLSchema-实例xsi:schemaLocation =http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd\">
< persistence-unit name =HelloWorld>
< jta-data-source> EjbMySql< / jta-data-source>
< class> model.MyUser< / class>
< / persistence-unit>
< / persistence>
modules / com / mysql / main / Modules.xml如下...
<?xml version =1.0encoding =UTF-8?>
<! -
〜JBoss,专业开源之家。
〜版权所有2010,红帽公司和个人贡献者
〜由@author标签指示。有关个人贡献者的完整列表,请参阅
〜发行版中的copyright.txt文件。
〜
〜这是免费软件;您可以根据GNU通用公共许可证的条款重新分配和/或修改
〜
〜由自由软件基金会发布;版本2.1的
〜许可证,或(在您的选择)任何更高版本。
〜
〜这个软件是分发的,希望它是有用的,
〜但没有任何保证;甚至没有
〜适销性或适用于特定用途的隐含担保。有关详细信息,请参阅GNU
〜小型通用公共许可证。
〜
〜您应该已经收到GNU Lesser General Public
〜许可证与该软件的副本;如果没有,请写入免费
〜Software Foundation,Inc.,51 Franklin St,Boston,Boston,MA
〜02110-1301 USA,或者参见FSF网站:http:// www。 fsf.org。
- >
< module xmlns =urn:jboss:module:1.0name =com.mysql.jdbc>
< resources>
< resource-root path =mysql-connector-java-5.1.18-bin.jar/>
< / resources>
<依赖关系>
< module name =javax.api/>
< / dependencies>
< / module>
Standalone.xml有以下条目...
< subsystem xmlns =urn:jboss:domain:datasources:1.0>
< datasources>
< datasource jndi-name =java:jboss / datasources / EjbMySqlpool-name =EjbMySqlenabled =trueuse-java-context =true>
< connection-url> jdbc:mysql:// localhost:3306 / ejbdb< / connection-url>
< driver> com.mysql< / driver>
< security>
< user-name>根< / user-name>
< password>根< / password>
< / security>
< / datasource>
< drivers>
< driver name =com.mysqlmodule =com.mysql.jdbc> < XA-数据源级> com.mysql.jdbc.Driver< / XA-数据源级> < /驱动器>
< / drivers>
< / datasources>
< / subsystem>
在我的项目中,我有/ WebContent / META-INF / services / mysql- connector-java-5.1.18-bin.jar
有没有人有任何想法?
谢谢! / p>
编辑:尝试...
< datasource jndi-name =java:jboss / datasources / EjbMySqlpool-name =EjbMySqlenabled =trueuse-java-context =true>
< connection-url> jdbc:mysql:// localhost:3306 / ejbdb< / connection-url>
< driver> com.mysql.jdbc.Driver< / driver>
< security>
< user-name>根< / user-name>
< password>根< / password>
< / security>
返回同样的错误。
在< JBOSS_HOME> /standalone/configuration/standalone.xml中
找到< subsystem xmlns = urn:jboss:domain:datasources:1.0>
标签,并在< datasources>
元素中添加以下内容:
< datasources>
< datasource jndi-name =java:jboss / datasources / MysqlDSpool-name =MysqlDSenabled =trueuse-java-context =true>
< connection-url> jdbc:mysql:// localhost:3306 / DATABASE_NAME< / connection-url>
< driver> com.mysql< / driver>
< security>
< user-name> USERNAME< / user-name>
< password> PASSWORD< / password>
< / security>
< / datasource>
< drivers>
< driver name =com.mysqlmodule =com.mysql>
< xa-datasource-class> com.mysql.jdbc.jdbc2.optional.MysqlXADataSource< / xa-datasource-class>
< / driver>
< / drivers>
< / datasources>
替换DATABASE_NAME,USERNAME和PASSWORD。
在< drivers>
元素内添加以下内容:
< driver name =com.mysqlmodule =com.mysql>
< xa-datasource-class> com.mysql.jdbc.jdbc2.optional.MysqlXADataSource< / xa-datasource-class>
< / driver>
现在,转到< JBOSS_HOME> / modules
并创建路径 com / mysql / main
将驱动程序的jar放在那里(例如mysql-connector-java-5.1.18-bin.jar)并创建文件 module.xml
包含以下内容:
< module xmlns = urn:jboss:module:1.1name =com.mysql>
< resources>
< resource-root path =mysql-connector-java-5.1.18-bin.jar/>
<! - 在这里插入资源 - >
< / resources>
<依赖关系>
< module name =javax.api/>
< module name =javax.transaction.api/>
< module name =javax.servlet.apioptional =true/>
< / dependencies>
< / module>
应该做的伎俩。
I'm deploying a really simple helloworld style EJB application. When doing so I get...
WARNING: -logmodule is deprecated. Please use the system property 'java.util.logging.manager' or the 'java.util.logging.LogManager' service loader.
13:15:54,638 INFO [org.jboss.modules] JBoss Modules version 1.1.1.GA
13:15:55,094 INFO [org.jboss.msc] JBoss MSC version 1.0.2.GA
13:15:55,175 INFO [org.jboss.as] JBAS015899: JBoss AS 7.1.0.Final "Thunder" starting
13:15:56,587 INFO [org.xnio] XNIO Version 3.0.3.GA
13:15:56,592 INFO [org.jboss.as.server] JBAS015888: Creating http management service using socket-binding (management-http)
13:15:56,602 INFO [org.xnio.nio] XNIO NIO Implementation Version 3.0.3.GA
13:15:56,614 INFO [org.jboss.remoting] JBoss Remoting version 3.2.2.GA
13:15:56,655 INFO [org.jboss.as.logging] JBAS011502: Removing bootstrap log handlers
13:15:56,661 INFO [org.jboss.as.configadmin] (ServerService Thread Pool -- 26) JBAS016200: Activating ConfigAdmin Subsystem
13:15:56,707 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 31) JBAS010280: Activating Infinispan subsystem.
13:15:56,793 INFO [org.jboss.as.connector] (MSC service thread 1-3) JBAS010408: Starting JCA Subsystem (JBoss IronJacamar 1.0.7.Final)
13:15:56,822 INFO [org.jboss.as.naming] (ServerService Thread Pool -- 38) JBAS011800: Activating Naming Subsystem
13:15:56,839 INFO [org.jboss.as.osgi] (ServerService Thread Pool -- 39) JBAS011940: Activating OSGi Subsystem
13:15:56,881 INFO [org.jboss.as.security] (ServerService Thread Pool -- 44) JBAS013101: Activating Security Subsystem
13:15:56,889 INFO [org.jboss.as.naming] (MSC service thread 1-1) JBAS011802: Starting Naming Service
13:15:56,898 INFO [org.jboss.as.mail.extension] (MSC service thread 1-2) JBAS015400: Bound mail session [java:jboss/mail/Default]
13:15:56,933 INFO [org.jboss.as.security] (MSC service thread 1-2) JBAS013100: Current PicketBox version=4.0.6.final
13:15:56,989 INFO [org.jboss.as.webservices] (ServerService Thread Pool -- 48) JBAS015537: Activating WebServices Extension
13:15:57,324 INFO [org.jboss.ws.common.management.AbstractServerConfig] (MSC service thread 1-2) JBoss Web Services - Stack CXF Server 4.0.1.GA
13:15:57,501 INFO [org.apache.coyote.http11.Http11Protocol] (MSC service thread 1-4) Starting Coyote HTTP/1.1 on http--127.0.0.1-8080
13:15:58,264 INFO [org.jboss.as.server.deployment.scanner] (MSC service thread 1-2) JBAS015012: Started FileSystemDeploymentService for directory /usr/bin/jboss-as-7.1.0.Final/standalone/deployments
13:15:58,265 INFO [org.jboss.as.remoting] (MSC service thread 1-1) JBAS017100: Listening on /127.0.0.1:4447
13:15:58,265 INFO [org.jboss.as.remoting] (MSC service thread 1-3) JBAS017100: Listening on /127.0.0.1:9999
13:15:58,272 INFO [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) JBAS015003: Found HelloWorld.war in deployment directory. To trigger deployment create a file called HelloWorld.war.dodeploy
13:15:58,581 INFO [org.jboss.as.controller] (Controller Boot Thread) JBAS014774: Service status report
JBAS014775: New missing/unsatisfied dependencies:
service jboss.jdbc-driver.com_mysql (missing) dependents: [service jboss.data-source.java:jboss/datasources/EjbMySql]
13:15:58,589 ERROR [org.jboss.as] (Controller Boot Thread) JBAS015875: JBoss AS 7.1.0.Final "Thunder" started (with errors) in 4548ms - Started 131 of 204 services (2 services failed or missing dependencies, 70 services are passive or on-demand)
It looks like I need to add an include somewhere, my code is very simple...
package server;
import java.io.IOException;
import java.io.PrintWriter;
import javax.ejb.EJB;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceUnit;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.MyUser;
/**
* Servlet implementation class HelloServlet
*/
@WebServlet("/HelloServlet")
public class HelloServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@EJB HelloBean bean;
@PersistenceUnit
EntityManagerFactory emF;
/**
* @see HttpServlet#HttpServlet()
*/
public HelloServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.print("<html><body>");
MyUser user = (MyUser)emF.createEntityManager().createQuery("select * from myuser").getResultList().get(0);
out.println("Username = " + user.getName());
out.print("</body></html>");
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
}
Persistance.xml is shown below...
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" 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">
<persistence-unit name="HelloWorld">
<jta-data-source>EjbMySql</jta-data-source>
<class>model.MyUser</class>
</persistence-unit>
</persistence>
modules/com/mysql/main/Modules.xml is as follows...
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ JBoss, Home of Professional Open Source.
~ Copyright 2010, Red Hat, Inc., and individual contributors
~ as indicated by the @author tags. See the copyright.txt file in the
~ distribution for a full listing of individual contributors.
~
~ This is free software; you can redistribute it and/or modify it
~ under the terms of the GNU Lesser General Public License as
~ published by the Free Software Foundation; either version 2.1 of
~ the License, or (at your option) any later version.
~
~ This software is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
~ Lesser General Public License for more details.
~
~ You should have received a copy of the GNU Lesser General Public
~ License along with this software; if not, write to the Free
~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->
<module xmlns="urn:jboss:module:1.0" name="com.mysql.jdbc">
<resources>
<resource-root path="mysql-connector-java-5.1.18-bin.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
</dependencies>
</module>
Standalone.xml has the following entry...
<subsystem xmlns="urn:jboss:domain:datasources:1.0">
<datasources>
<datasource jndi-name="java:jboss/datasources/EjbMySql" pool-name="EjbMySql" enabled="true" use-java-context="true">
<connection-url>jdbc:mysql://localhost:3306/ejbdb</connection-url>
<driver>com.mysql</driver>
<security>
<user-name>root</user-name>
<password>root</password>
</security>
</datasource>
<drivers>
<driver name="com.mysql" module="com.mysql.jdbc"> <xa-datasource-class>com.mysql.jdbc.Driver</xa-datasource-class> </driver>
</drivers>
</datasources>
</subsystem>
In my project, I have the MySQL jar in /WebContent/META-INF/services/mysql-connector-java-5.1.18-bin.jar
Does anyone have any ideas?
Thanks!
EDIT: Tried...
<datasource jndi-name="java:jboss/datasources/EjbMySql" pool-name="EjbMySql" enabled="true" use-java-context="true">
<connection-url>jdbc:mysql://localhost:3306/ejbdb</connection-url>
<driver>com.mysql.jdbc.Driver</driver>
<security>
<user-name>root</user-name>
<password>root</password>
</security>
comes back with the same error.
In <JBOSS_HOME>/standalone/configuration/standalone.xml
find the <subsystem xmlns="urn:jboss:domain:datasources:1.0">
tag and add the following inside the <datasources>
element:
<datasources>
<datasource jndi-name="java:jboss/datasources/MysqlDS" pool-name="MysqlDS" enabled="true" use-java-context="true">
<connection-url>jdbc:mysql://localhost:3306/DATABASE_NAME</connection-url>
<driver>com.mysql</driver>
<security>
<user-name>USERNAME</user-name>
<password>PASSWORD</password>
</security>
</datasource>
<drivers>
<driver name="com.mysql" module="com.mysql">
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
Replace DATABASE_NAME,USERNAME and PASSWORD apporpriately.
Inside the <drivers>
element add the following:
<driver name="com.mysql" module="com.mysql">
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>
Now, go to <JBOSS_HOME>/modules
and create the path com/mysql/main
put the driver's jar there (eg. mysql-connector-java-5.1.18-bin.jar) and create the file module.xml
with the following contents:
<module xmlns="urn:jboss:module:1.1" name="com.mysql">
<resources>
<resource-root path="mysql-connector-java-5.1.18-bin.jar"/>
<!-- Insert resources here -->
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.servlet.api" optional="true"/>
</dependencies>
</module>
That should do the trick.
这篇关于通过JBoss 7.1部署EJB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!