根據公司工作需要,這個元旦開始才選定用jBPM工作流引擎,什么東西都是一片空白,而jBPM的example WebSale程序是選用的技術卻是jsf, hibernate,一時無所適從。
沒辦法只好硬著頭皮啃下去,jsf,hibernate
這兩天都快抓狂了!!!無論如何都不能使用自己創建的mysql數據庫
就快放棄的時候,老天終于眷顧我啦!!!
根據一些前人的blog和工作流群上的人的指點,現總結以下兩種配置用mysql數據庫datasource的方法。
(一)需要改jBPM源碼(這個方法不太好,但是可以讀讀源碼,了解機制)
配置連接 MySQL
1. 在jbpm-3.0\lib目錄下 創建mysql目錄
2. 將 mysql數據庫驅動 (mysql-connector-java-3.1.7-bin.jar) copy到mysql 目錄
3. 在 mysql 中創建一個數據庫,數據庫名字
4. 在jbpm-3.0\src\resources目錄下創建mysql目錄
5. 把兩個配置文件 (create.db.hibernate.properties, identity.db.xml) 從hsqldb目錄下 拷貝到mysql目錄
create.db.hibernate.properties文件中內容參考如下:
# these properties are used by the build script to create
# a hypersonic database in the build/db directory that contains
# the jbpm tables and a process deployed in there
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.connection.url=jdbc:mysql://localhost:3306/jbpm
hibernate.connection.username=jbpm
hibernate.connection.password=jbpm
hibernate.c3p0.min_size=1
hibernate.c3p0.max_size=3
hibernate.show_sql=true
6. 在jbpm\lib下創建mysql目錄,放進mysql的jdbc driver
7.修改build.deploy.xml 文件中create.db task
<target name="create.db" depends="declare.jbpm.tasks, db.clean" description="creates a hypersonic database with the jbpm tables and loads the processes in there">
<jbpmschema actions="create" properties="${basedir}/src/resources/mysql/create.db.hibernate.properties"/>
<loadidentities file="${basedir}/src/resources/mysql/identity.db.xml" properties="${basedir}/src/resources/mysql/create.db.hibernate.properties"/>
<ant antfile="build.xml" target="build.processes" inheritall="false" />
<deploypar properties="${basedir}/src/resources/mysql/create.db.hibernate.properties">
<fileset dir="build" includes="*.par" />
</deploypar>
</target>
因為 Hibernate 不能將它的SessionFactory與tomcat的jndi 綁定 , 我們直接在源碼中修改
9. 打開源文件 JbpmSessionFactory.java, 在 getInstance() 方法里, 刪除下面代碼
InitialContext initialContext = new InitialContext();
Object o = initialContext.lookup(jndiName);
將下面這行
instance = (JbpmSessionFactory)
PortableRemoteObject.narrow(o, JbpmSessionFactory.class);
替換為 instance = (JbpmSessionFactory)
PortableRemoteObject.narrow(
new JbpmSessionFactory(createConfiguration()), JbpmSessionFactory.class);
10.在 createConfiguration(String configResource) 方法里, 注釋掉這段代碼
String hibernatePropertiesResource =
JbpmConfiguration.getString("jbpm.hibernate.properties");
if (hibernatePropertiesResource!=null)
{
Properties hibernateProperties = new Properties();
try
{
hibernateProperties.load(
ClassLoaderUtil.getStream(hibernatePropertiesResource) );
}
catch (IOException e)
{
e.printStackTrace();
throw new RuntimeException(
"couldn't load the hibernate properties" +
" from resource '"hibernatePropertiesResource"'", e);
}
log.debug("overriding hibernate properties with "+ hibernateProperties); configuration.setProperties(hibernateProperties);
}
同時加入下面的代碼
configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect"); configuration.setProperty("hibernate.connection.driver_class", "com.mysql.jdbc.Driver"); configuration.setProperty("hibernate.connection.url", "jdbc:mysql://localhost:3306/";); configuration.setProperty("hibernate.connection.username", "");
configuration.setProperty("hibernate.connection.password", "");
configuration.setProperty("hibernate.connection.pool_size", "15");
11.這種方法需要先開starter-kit中的jboss,然后build websale,最后deploy
參考文章:
http://mdvjiangbin.bokee.com/3185679.html
http://www.aygfsteel.com/znjqolf/archive/2005/12/19/24654.html
還有好多,查過之后都忘了鏈接了,謝謝前人的總結!
方法二:
1,在starter-kit server中部署的jbpm應用里的deploy目錄中創建mysql-ds.xml
文件內容參考如下:
<?xml version="1.0" encoding="UTF-8"?>
<!-- The Hypersonic embedded database JCA connection factory config
$Id: hsqldb-ds.xml,v 1.15 2004/09/15 14:37:40 loubyansky Exp $ -->
<datasource>
<local-tx-datasource>
<!-- The jndi name of the DataSource, it is prefixed with java:/ -->
<!-- Datasources are not available outside the virtual machine -->
<jndi-name>DefaultDS</jndi-name>
<!-- for tcp connection, allowing other processes to use the hsqldb
database. This requires the org.jboss.jdbc.HypersonicDatabase mbean.
<connection-url>jdbc:hsqldb:hsql://localhost:1701</connection-url>
-->
<!-- for totally in-memory db, not saved when jboss stops.
The org.jboss.jdbc.HypersonicDatabase mbean necessary
<connection-url>jdbc:hsqldb:.</connection-url>
-->
<!-- for in-process persistent db, saved when jboss stops. The
org.jboss.jdbc.HypersonicDatabase mbean is necessary for properly db shutdown
-->
<connection-url>jdbc:mysql://localhost:3306/jbpm</connection-url>
<!-- The driver class -->
<driver-class>com.mysql.jdbc.Driver</driver-class>
<!-- The login and password -->
<user-name>jbpm</user-name>
<password>jbpm</password>
<!--example of how to specify class that determines if exception means connection should be destroyed-->
<!--exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.DummyExceptionSorter</exception-sorter-class-name-->
<!-- this will be run before a managed connection is removed from the pool for use by a client-->
<!--<check-valid-connection-sql>select * from something</check-valid-connection-sql> -->
<!-- The minimum connections in a pool/sub-pool. Pools are lazily constructed on first use -->
<min-pool-size>5</min-pool-size>
<!-- The maximum connections in a pool/sub-pool -->
<max-pool-size>20</max-pool-size>
<!-- The time before an unused connection is destroyed -->
<!-- NOTE: This is the check period. It will be destroyed somewhere between 1x and 2x this timeout after last use -->
<!-- TEMPORARY FIX! - Disable idle connection removal, HSQLDB has a problem with not reaping threads on closed connections -->
<idle-timeout-minutes>0</idle-timeout-minutes>
</local-tx-datasource>
<metadata>
<type-mapping>mySQL</type-mapping>
</metadata>
</datasource>
2,刪除該目錄有關hsqldb 設置datasource的兩個xml文件。
3,edit 上一目錄conf下的standardjaws.xml中的這段
<datasource>java:/DefaultDS</datasource>
<type-mapping>mySQL</type-mapping>
讓type-mapping對應mysql-ds.xml中的type-mapping
Step 4: JMS configuration descriptors
a) Remove hsqldb-jdbc2-service.xml from folder deploy/jms. Save this file somewhere else.
b) Copy mysql-jdbc2-service.xml from folder docs/example/jms to deploy/jms.
c) Edit mysql-jdbc2-service.xml and change the datasource name if applicable. In my configuration I don't use HSQL at all so I configured the default datasource DefaultDS for MySQL. In this file, change mySQLDS to DefaultDS. Note that datasource names are case sensitive.
Step 5: Install MySQL Java Connector
Download MySQL Connector/J and place the file mysql-connector-java-3.0.15-ga-bin.jar in the lib folder of the server.
!!!同時需要修改deploy中jbpm.sar文件夾里的jbpm.sar.cfg.jar文件,更新該文件里面的數據庫配置
參考文章:
http://wiki.jboss.org/wiki/Wiki.jsp?page=SetUpAMysqlDatasource
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3861605
只有注冊用戶登錄后才能發表評論。 | ||
![]() |
||
網站導航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
|
||
相關文章:
|
||