【问题标题】:'New missing/unsatisfied dependencies' error with c3p0 pooling in JBoss EAP 6.3.0.GA (AS 7.4.0.Final-redhat-19) envJBoss EAP 6.3.0.GA (AS 7.4.0.Final-redhat-19) 环境中 c3p0 池的“新缺失/不满足的依赖项”错误
【发布时间】:2015-08-26 10:23:38
【问题描述】:

我想通过Mbean 将c3p0 连接池集成到JBoss EAP 6.3.0.GA (AS 7.4.0.Final-redhat-19) 服务中。谷歌搜索了一些示例并尝试将其集成。 这是我的配置。 将c3p0 jars 和module.xml 添加到模块目录{JBOSS_HOME}/modules/system/layers/base/com/c3p0/main、module.xml 配置中:

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="com.c3p0">
    <resources>
        <resource-root path="c3p0-0.9.5.1.jar"/>
        <resource-root path="c3p0-oracle-thin-extras-0.9.5.1.jar"/>
        <resource-root path="mchange-commons-java-0.2.10.jar"/>
    </resources>
    <dependencies>
        <module name="javax.api"/>
        <module name="javax.transaction.api"/>
    </dependencies>
</module>

在standalone.xml 中将c3p0 添加到全局模块(类路径)中:

<subsystem xmlns="urn:jboss:domain:ee:1.2">
    <global-modules>
        <module name="com.c3p0" slot="main"/>
    </global-modules>
 </subsystem>

将服务文件添加到{JBOSS_HOME}/standalone/deployments/c3p0-service.xml:

<?xml version="1.0" encoding="UTF-8"?>
<server xmlns="urn:jboss:service:7.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="urn:jboss:service:7.0 jboss-service_7_0.xsd">
<mbean code="com.mchange.v2.c3p0.jboss.C3P0PooledDataSource"
     name="jboss.jca:service=DataSourceBinding,name=jdbc/myDB">
     <attribute name="JndiName">java:jdbc/myDB</attribute>
     <attribute name="JdbcUrl">jdbc:oracle:thin:@server.com:1521:sid</attribute>
     <attribute name="DriverClass">oracle.jdbc.driver.OracleDriver</attribute>
     <attribute name="User">username</attribute>
     <attribute name="Password">password</attribute>
     <attribute name="MaxPoolSize">20</attribute>
     <attribute name="AcquireRetryAttempts">0</attribute>
     <depends>jboss:service=Naming</depends>
</mbean>
</server>

将数据源配置与standalone.xml分开放入{JBOSS_HOME}/standalone/deployments/c3p0-ds.xml,ojdbc6.jar放入同一个目录。

<datasources xmlns="http://www.jboss.org/ironjacamar/schema">
            <datasource jta="false" jndi-name="java:/jdbc/myDB" pool-name="myDB" enabled="true" use-ccm="false" use-java-context="true">
                    <connection-url>jdbc:oracle:thin:@server.com:1521:sid</connection-url>
                    <driver-class>oracle.jdbc.OracleDriver</driver-class>
                    <driver>ojdbc6.jar</driver>
                    <security>
                        <user-name>username</user-name>
                        <password>password</password>
                    </security>
                    <pool>
                        <min-pool-size>30</min-pool-size>
                        <max-pool-size>300</max-pool-size>
                        <prefill>true</prefill>
                    </pool>
                     <timeout>
                        <blocking-timeout-millis>120000</blocking-timeout-millis>
                        <idle-timeout-minutes>5</idle-timeout-minutes>
                    </timeout>
                    <validation>
                        <validate-on-match>false</validate-on-match>
                        <background-validation>false</background-validation>
                    </validation>
                    <statement>
                        <share-prepared-statements>false</share-prepared-statements>
                    </statement>
                </datasource>
                </datasources>

web.xml

<resource-ref>
    <description>
    </description>
    <res-ref-name>jdbc/myDB</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>

jboss-web.xml

<resource-ref>
    <res-ref-name>jdbc/myDB</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <jndi-name>java:/jdbc/myDB</jndi-name>
</resource-ref>

在部署结束时出现错误: New missing/unsatisfied dependencies: service jboss.mbean.service.jboss:service=Naming.create (missing) dependents: [service jboss.mbean.service."jboss.jca:service=DataSourceBinding,name=jdbc/myDB".create] service jboss.mbean.service.jboss:service=Naming.start (missing) dependents: [service jboss.mbean.service."jboss.jca:service=DataSourceBinding,name=jdbc/myDB".start]

我尝试了许多 mbean 'name' 属性的变体,但似乎问题出在依赖项中......需要帮助我做错了什么。 任何帮助将不胜感激!

编辑:找到另一种方法,如下所述。

【问题讨论】:

    标签: jboss jboss7.x c3p0


    【解决方案1】:

    使用另一种解决方案如何将 c3p0 连接池添加到 JBoss EAP 6.3.0.GA(AS 7.4.0.Final-redhat-19,因为标签在 JBoss 7 上不起作用(正如我从 this 主题中了解到的那样) . 我使用了Service Archive (SAR) 方法。 首先,我们需要将c3p0 模块添加到具有指定JAR 的JBoss(不记得是否需要所有JAR):

    <?xml version="1.0" encoding="UTF-8"?>
    <module xmlns="urn:jboss:module:1.1" name="com.c3p0">
        <resources>
            <resource-root path="c3p0-0.9.5.1.jar"/>
            <resource-root path="c3p0-oracle-thin-extras-0.9.5.1.jar"/>
            <resource-root path="mchange-commons-java-0.2.10.jar"/>
        </resources>
        <dependencies>
            <module name="javax.api"/>
            <module name="javax.transaction.api"/>      
            <module name="com.oracle.ojdbc6"/>
            <module name="org.hibernate"/>
        </dependencies>
    </module>
    

    将c3p0 全局模块添加到standalone.xml(如问题部分)。 将数据源添加到standalone.xml

       <subsystem xmlns="urn:jboss:domain:datasources:1.2">
            <datasources>
                <datasource jta="false" jndi-name="java:/jdbc/myDB" pool-name="myDB" enabled="true" use-ccm="false">
                    <connection-url>jdbc:oracle:thin:@server.com:1521:sid</connection-url>
                   <driver-class>oracle.jdbc.OracleDriver</driver-class>
                    <driver>oracle</driver>
                  <pool>
                        <min-pool-size>30</min-pool-size>
                        <max-pool-size>300</max-pool-size>
                        <prefill>true</prefill>
                    </pool> 
                    <security>
                        <user-name>username</user-name>
                        <password>password</password>
                    </security>
                    <validation>
                        <validate-on-match>false</validate-on-match>
                        <background-validation>false</background-validation>
                    </validation>
                    <timeout>
                        <blocking-timeout-millis>120000</blocking-timeout-millis>
                        <idle-timeout-minutes>5</idle-timeout-minutes>
                    </timeout>
                    <statement>
                        <share-prepared-statements>true</share-prepared-statements>
                    </statement>
                </datasource>
                <drivers>        
                    <driver name="oracle" module="com.oracle.ojdbc6">
                        <datasource-class>oracle.jdbc.driver.OracleDriver</datasource-class>
                    </driver>
                </drivers>
            </datasources>
    

    在部署中创建文件夹,例如 c3p0Pool.sar。创建META-INF 文件夹{JBOSS_HOME}/standalone/deployments/c3p0Pool.sar/META-INF。在此文件夹中创建 jboss-service.xml 文件内容:

    <?xml version="1.0" encoding="UTF-8"?>
    <server xmlns="urn:jboss:service:7.0"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="urn:jboss:service:7.0 jboss-service_7_0.xsd">
    <mbean code="sar.C3P0PoolBinding" name="c3p0:service=c3p0Pool">
     <attribute name="JndiName">jdbc/myDB</attribute>
     <attribute name="JdbcUrl">jdbc:oracle:thin:@server.com:1521:sid</attribute>
     <attribute name="DriverClass">oracle.jdbc.driver.OracleDriver</attribute>
     <attribute name="User">username</attribute>
     <attribute name="Password">password</attribute>
     <attribute name="MaxPoolSize">20</attribute>
     <attribute name="AcquireIncrement">0</attribute>
    </mbean>
    </server>
    

    创建类和接口(类名要正确命名:ClassName 和 ClassNameMBean):

    package sar;
    
    import java.util.logging.Level;
    import java.util.logging.Logger;
    
    import javax.naming.NamingException;
    
    import com.mchange.v2.c3p0.jboss.C3P0PooledDataSource;
    
    public class C3P0PoolBinding implements C3P0PoolBindingMBean {
    
        private String JndiName;
        private String JdbcUrl;
        private String DriverClass;
        private String User;
        private String Password;
        private int MaxPoolSize;
        private int AcquireIncrement;
        private C3P0PooledDataSource c3p0;
    
        public C3P0PoolBinding() {}
    
        public String getJndiName() {
            return this.JndiName;
        }
    
        public void setJndiName(String parameter) throws NamingException {
            this.JndiName = parameter;
        }
    
        public String getJdbcUrl() {
            return this.JdbcUrl;
        }
    
        public void setJdbcUrl(String jdbcUrl) throws NamingException {
            this.JdbcUrl = jdbcUrl;
        }
    
        public String getDriverClass() {
            return this.DriverClass;
        }
    
        public void setDriverClass(String driverClass) throws NamingException {
            this.DriverClass = driverClass;
        }
    
        public String getUser() {
            return this.User;
        }
    
        public void setUser(String user) throws NamingException {
            this.User = user;
        }
    
        public String getPassword() {
            return this.Password;
        }
    
        public void setPassword(String password) throws NamingException {
            this.Password = password;
        }
    
        public int getMaxPoolSize() {
            return this.MaxPoolSize;
        }
    
        public void setMaxPoolSize(int maxPoolSize) throws NamingException {
            this.MaxPoolSize = maxPoolSize;
        }
    
        public int getAcquireIncrement() {
            return this.AcquireIncrement;
        }
    
        public void setAcquireIncrement(int acquireIncrement) throws NamingException {
            this.AcquireIncrement = acquireIncrement;
        }
    
        public void start() throws Exception {
            Logger.getLogger(C3P0PoolBinding.class.getName()).log(Level.INFO, "Enabling c3p0 connection Pool");
            try {
                c3p0 = new C3P0PooledDataSource();
                c3p0.setJndiName(JndiName);
                c3p0.setJdbcUrl(JdbcUrl);
                c3p0.setDriverClass(DriverClass);
                c3p0.setUser(User);
                c3p0.setPassword(Password);
                c3p0.setMaxPoolSize(MaxPoolSize);
                c3p0.setAcquireIncrement(AcquireIncrement);
                c3p0.start();
            } catch (NamingException ex) {
                ex.printStackTrace();
            }
        }
    
        public void stop() throws Exception {
            Logger.getLogger(C3P0PoolBinding.class.getName()).log(Level.INFO, "Stopping c3p0 connection Pool");
            c3p0.destroy();
        }
    }
    

    界面:

    package sar;
    
    import javax.naming.NamingException;
    
    public interface C3P0PoolBindingMBean {
    
        public String getJndiName();
    
        public void setJndiName(String JndiName) throws NamingException;
    
        public String getJdbcUrl();
    
        public void setJdbcUrl(String jdbcUrl) throws NamingException;
    
        public String getDriverClass();
    
        public void setDriverClass(String driverClass) throws NamingException;
    
        public String getUser();
    
        public void setUser(String user) throws NamingException;
    
        public String getPassword();
    
        public void setPassword(String password) throws NamingException;
    
        public int getMaxPoolSize();
    
        public void setMaxPoolSize(int maxPoolSize) throws NamingException;
    
        public int getAcquireIncrement();
    
        public void setAcquireIncrement(int acquireIncrement) throws NamingException;
    }
    

    最后,用这些类创建 JAR 文件并将其放置到 {JBOSS_HOME}/standalone/deployments/c3p0Pool.sar/c3p0Jar.jar

    现在 c3p0 池应该可以正常工作了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-03-24
      • 1970-01-01
      • 1970-01-01
      • 2015-03-07
      • 1970-01-01
      • 2017-11-05
      • 2014-04-22
      相关资源
      最近更新 更多