没有可写属性' URL'在课堂上' com.mchange.v2.c3p0.ComboPooledDataSource'

时间:2016-02-02 13:22:00

标签: mysql hibernate datasource c3p0 bitronix

我在项目中配置了以下c3p0设置。但是在执行jar文件时,我发现"没有可写属性"。请告诉我如何解决这个问题。

配置: -

dataSource.setClassName("com.mchange.v2.c3p0.ComboPooledDataSource");        
        dataSource.getDriverProperties().setProperty("driverClass", properties.getProperty("jdbc.driver"));
        dataSource.setUniqueName(properties.getProperty("jbpm.uniquename"));
        dataSource.setMaxPoolSize(Integer.parseInt(properties.getProperty("jbpm.max")));
        dataSource.setAllowLocalTransactions(true);
        dataSource.getDriverProperties().setProperty("URL", properties.getProperty("jbpm.url"));
    dataSource.getDriverProperties().setProperty("user", properties.getProperty("jbpm.username"));
        dataSource.getDriverProperties().setProperty("password", properties.getProperty("jbpm.password"));
        dataSource.getDriverProperties().setProperty("acquireIncrement", properties.getProperty("jdbc.acquireincrement"));
        dataSource.getDriverProperties().setProperty("preferredTestQuery", properties.getProperty("jdbc.preferredtestquery"));
        dataSource.getDriverProperties().setProperty("breakAfterAcquireFailure", properties.getProperty("jdbc.breakafteracquirefailure"));
        dataSource.getDriverProperties().setProperty("acquireRetryAttempts", properties.getProperty("jdbc.acquireretryattempts"));
        dataSource.getDriverProperties().setProperty("acquireRetryDelay", properties.getProperty("jdbc.acquireretrydelay"));
        dataSource.getDriverProperties().setProperty("loginTimeout", properties.getProperty("jdbc.logintimeout"));
        dataSource.getDriverProperties().setProperty("idleConnectionTestPeriod", properties.getProperty("jdbc.dleconnectiontestperiod"));
        dataSource.getDriverProperties().setProperty("maxPoolSize", properties.getProperty("jdbc.maxpoolsize"));
        dataSource.getDriverProperties().setProperty("minPoolSize", properties.getProperty("jdbc.minpoolsize"));

错误日志: -

bitronix.tm.resource.ResourceConfigurationException: cannot create JDBC datasource named java:jboss/datasources/DS
    at bitronix.tm.resource.jdbc.PoolingDataSource.init(PoolingDataSource.java:80)
    at com.tnq.messageq.DataSource.init(DataSource.java:60)
    at com.tnq.messageq.IntegrationConsumer.main(IntegrationConsumer.java:77)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.simontuffs.onejar.Boot.run(Boot.java:340)
    at com.simontuffs.onejar.Boot.main(Boot.java:166)
Caused by: bitronix.tm.utils.PropertyException: no writeable property 'URL' in class 'com.mchange.v2.c3p0.ComboPooledDataSource'
    at bitronix.tm.utils.PropertyUtils.getSetter(PropertyUtils.java:318)
    at bitronix.tm.utils.PropertyUtils.setDirectProperty(PropertyUtils.java:217)
    at bitronix.tm.utils.PropertyUtils.setProperty(PropertyUtils.java:83)
    at bitronix.tm.resource.common.XAPool.createXAFactory(XAPool.java:314)
    at bitronix.tm.resource.common.XAPool.<init>(XAPool.java:63)
    at bitronix.tm.resource.jdbc.PoolingDataSource.buildXAPool(PoolingDataSource.java:89)
    at bitronix.tm.resource.jdbc.PoolingDataSource.init(PoolingDataSource.java:76)

感谢您对此进行调查..

2 个答案:

答案 0 :(得分:1)

ComboPooledDataSource有一个名为JdbcUrl.Hence的属性,您可以尝试使用它而不是url。

    dataSource.getDriverProperties().setProperty("jdbcUrl, properties.getProperty("jbpm.url"));

希望这有帮助。

答案 1 :(得分:0)

网址问题已解决。但在那之后,我发现无法找到名字的绑定对象&#39;。请检查并告诉我。

对于c3p0迁移,我更改了PoolingDataSource&#39;到了&#39; ComboPooledDataSource&#39;,之后我在init方法中配置了以下设置。

<强>代码: -

public static void init() throws Exception {
        setPropertyMap();
        properties = new Properties();
        FileInputStream fileInput = new FileInputStream(new File("/home/data/settings."+map.get(System.getenv("spring_profiles_active"))+".properties"));
        properties.load(fileInput);
        ComboPooledDataSource dataSource = new ComboPooledDataSource();
        dataSource.setDriverClass("com.mchange.v2.c3p0.ComboPooledDataSource");  
        dataSource.setJdbcUrl(properties.getProperty("jbpm.url"));
        dataSource.setUser(properties.getProperty("jbpm.username"));
        dataSource.setPassword(properties.getProperty("jbpm.password"));
        dataSource.setAcquireIncrement(Integer.parseInt(properties.getProperty("jdbc.acquireincrement")));
        dataSource.setAcquireRetryDelay(Integer.parseInt(properties.getProperty("jdbc.acquireretrydelay")));
        dataSource.setIdleConnectionTestPeriod(Integer.parseInt(properties.getProperty("jdbc.dleconnectiontestperiod")));
        dataSource.setMaxPoolSize(Integer.parseInt(properties.getProperty("jdbc.maxpoolsize")));
        dataSource.setMinPoolSize(Integer.parseInt(properties.getProperty("jdbc.minpoolsize")));
    }

错误日志: -

Caused by: org.hibernate.HibernateException: Could not find datasource
        at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:79)
        at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:143)
        at org.hibernate.ejb.InjectionSettingsFactory.createConnectionProvider(InjectionSettingsFactory.java:51)
        at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:90)
        at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2863)
        at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2859)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1870)
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:906)
        ... 68 more
Caused by: javax.naming.NameNotFoundException: unable to find a bound object at name 'java:jboss/datasources/DS'
        at bitronix.tm.jndi.BitronixContext.lookup(BitronixContext.java:83)
        at javax.naming.InitialContext.lookup(InitialContext.java:411)
        at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:75)
        ... 75 more
JarClassLoader: Warning: com/mchange/Debug.class in lib/c3p0-0.9.5.1.jar is

<强>的persistence.xml: -

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<persistence version="1.0"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
                                 http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd
                                 http://java.sun.com/xml/ns/persistence/orm 
                                 http://java.sun.com/xml/ns/persistence/orm_1_0.xsd"
             xmlns:orm="http://java.sun.com/xml/ns/persistence/orm"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns="http://java.sun.com/xml/ns/persistence">
    <persistence-unit name="org.jbpm.persistence.jpa.testcon">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>java:jboss/datasources/DS</jta-data-source>
        <mapping-file>META-INF/JBPMorm.xml</mapping-file>
        <class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class>
        <class>org.drools.persistence.info.SessionInfo</class>
        <class>org.drools.persistence.info.WorkItemInfo</class>
        <class>org.jbpm.process.audit.ProcessInstanceLog</class>
        <properties>
            <property name="hibernate.max_fetch_depth" value="3"/>
            <!--<property name="hibernate.hbm2ddl.auto" value="validate" />-->
            <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.BTMTransactionManagerLookup" />
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
        </properties>
    </persistence-unit>
</persistence>

<强> web.xml中: -

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/applicationContext.xml
        </param-value>
    </context-param>
    <filter>
        <filter-name>CORS</filter-name>
        <filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
        <init-param>
            <param-name>cors.supportedMethods</param-name>
            <param-value>GET, POST, HEAD, PUT, DELETE, OPTIONS</param-value>
        </init-param>
        <init-param>
            <param-name>cors.allowOrigin</param-name>
            <param-value>*</param-value>
        </init-param>
        <init-param>
            <param-name>cors.supportedHeaders</param-name>
            <param-value>Origin, X-Requested-With, Content-Type</param-value>
        </init-param>
        <init-param>
            <param-name>cors.allowGenericHttpRequests</param-name>
            <param-value>true</param-value>
        </init-param>
        <init-param>
            <param-name>cors.exposedHeaders</param-name>
            <param-value>Date</param-value>
        </init-param>
    </filter>
    <filter>
        <filter-name>hibernateFilter</filter-name>
        <filter-class>com.test.hibernate.HibernateFilter</filter-class>
        <init-param>
            <param-name>singleSession</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>hibernateFilter</filter-name>
        <url-pattern>*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>ERROR</dispatcher>
    </filter-mapping>
    <filter-mapping>
        <filter-name>CORS</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <servlet>
        <servlet-name>Test</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Test</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
<!-- To be used only when we need to deploy multiple wars in one container -->
    <env-entry>
        <env-entry-name>spring.profiles.active</env-entry-name>
        <env-entry-type>java.lang.String</env-entry-type>
        <env-entry-value>testuat</env-entry-value>
    </env-entry>
</web-app>

主程序调用init方法。

    public static void main(String[] argv) {
        try {
                DataSource.init();
                applicationContext = new ClassPathXmlApplicationContext("classpath:/applicationContext.xml");
..........
        }
        catch (Exception e) {
                e.printStackTrace();
                log.error(e.getStackTrace());
            }
        }

感谢您对此进行调查..