2012-02-28 179 views
5

我正在部署一个非常简单的helloworld风格的EJB应用程序。这样做时,我得到...通过JBoss 7.1部署EJB

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) 

它看起来像我需要补充的地方包括,我的代码是非常简单的...

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如下...

<?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> 

模块/ COM/MySQL的/主/ Modules.xml如下...

<?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具有以下条目...

<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> 

在我的项目,我在/WebContent/META-INF/services/mysql-connector-java-5.1.18-bin MySQL的罐子。罐子

有没有人有任何想法?

谢谢!

编辑:尝试...

<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> 

回来了同样的错误。

+0

尝试更改您的驱动程序名称为“com.mysql.jdbc.Driver”。 – 2012-02-28 13:24:36

+0

尝试过这种更新的问题,但没有解决任何问题:< – david99world 2012-02-28 13:28:06

回答

6

<JBOSS_HOME>/standalone/configuration/standalone.xml找到<subsystem xmlns="urn:jboss:domain:datasources:1.0">标签和里面添加了以下<datasources>元素:

<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> 

适当替换DATABASE_NAME,USERNAME和PASSWORD。

<drivers>元素中添加以下内容:。

<driver name="com.mysql" module="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.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> 

这应该做的伎俩。

+0

我按照你的建议做了,但我得到的错误... http://pastebin.com/5rRPnSKu和所有的XML在语法上是正确的,因为它打开铬等罚款。 standalone.xml是http://pastebin.com/S8esfvxC – david99world 2012-03-12 11:01:56

+0

您应该将标记放在元素内。我已编辑我的答案 – Efthymis 2012-03-13 10:13:33

+0

复制此,仍然得到完全相同的错误队友。 JBAS014775:新的缺失/不满意的依赖关系: 服务jboss.jdbc-driver.com_mysql(缺少)依赖项:[服务jboss.data-source.java:jboss/datasources/MysqlDS] – david99world 2012-03-13 16:17:52

0

在JBoss 7中,为创建数据源和安装JDBC驱动程序而更改了一些配置细节。看看这个迁移guide,在“定义数据源”和“安装JDBC驱动程序”部分。

+0

啊,我的jboss_home中没有/ server目录,我有appclient,bin,bundles,docs,domain,modules,standalone,welcome-content – david99world 2012-02-28 13:39:10

+0

我更新了我的答案。我忘记了在JBoss 7中,目录结构发生了很大变化。 – 2012-02-28 13:55:25

+0

啊,据我所知,一切都应该是正确的,jar是在/ webcontent/meta-inf/services中按要求的,清单和独立的xml文件也是最新的。 – david99world 2012-02-28 14:12:22

3

我认为你需要的数据源中standalone.xml与驱动模块就像下面的例子关联(取自here

 <datasources> 
      <datasource jndi-name="java:jboss/datasources/ExampleDS" enabled="true" use-java-context="true" pool-name="H2DS"> 
       <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url> 
       <driver>h2</driver> 
       <pool></pool> 
       <security> 
        <user-name>sa</user-name> 
        <password>sa</password> 
       </security> 
       <validation></validation> 
       <timeout></timeout> 
       <statement></statement> 
      </datasource> 
      <drivers> 
       <driver name="h2" module="com.h2database.h2"> 
        <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class> 
       </driver> 
       <driver name="mysql" module="com.mysql.jdbc"> <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class> </driver> 
      </drivers> 
     </datasources> 

在数据源的驱动元件在此引用驱动程序定义驱动元件,这本身就您所定义的模块和类的引用,这就是我如何使用它,以及它为我工作在JBoss 7.1。

+0

嗨,更改我的代码(从上面可以看到),将其设置在standalone.xml中,但不幸的是它仍然存在相同的问题。 – david99world 2012-03-07 16:44:10

+1

@ david99world根据你的module.xml,你的模块的名字是com.mysql,而不是你在standalone.xml中引用的com.mysql.jdbc – ftr 2012-03-07 21:15:15

+0

我同意。 以便它匹配 2012-03-11 21:49:37

0

是驱动程序的版本。更改为新版本。相信,只有它! 我将驱动程序mysql-connector-java-5.0.4-bin.jar更改为mysql-connector-java-5.1.25-bin.jar,然后问题就解决了。