版本jboss-4.0.2,
1、编译duke bank如下
ant -f jboss-build.xml package-ejb
prepare:
compile:
[javac] Compiling 63 source files to F:\j2eetutorial14\examples\bank\build
[jrc] Compiling 2 report design files.
[jrc] log4j:WARN No appenders could be found for logger (org.apache.commons.digester.Digester.sax).
[jrc] log4j:WARN Please initialize the log4j system properly.
[jrc] File : F:\j2eetutorial14\examples\bank\web\reports\BankStatementReport.jrxml ... OK.
[jrc] File : F:\j2eetutorial14\examples\bank\web\reports\AccountHistoryReport.jrxml ... OK.
2、使用BMP方式,数据库采用自带的HSQL,修改hsqldb-ds.xml三处:
注释掉jdbc:hsqldb:${jboss.server.data.dir}${/}hypersonic${/}localDB
增加 jdbc:hsqldb:hsql://localhost:1701
注释掉
name="jboss:service=Hypersonic,database=localDB">
localDB
true
增加
name="jboss:service=Hypersonic">
1701
true
default
false
true
注释掉DefaultDS
增加 jdbc/BankDB
3、启动jboss,只出现一个error
15:46:50,859 ERROR [URLDeploymentScanner] Incomplete Deployment listing:
--- MBeans waiting for other MBeans ---
............
............
............
ObjectName: jboss:database=localDB,service=Hypersonic
State: NOTYETINSTALLED
Depends On Me:
jboss.jca:name=jdbc/BankDB,service=ManagedConnectionFactory
15:46:51,078 INFO [Http11Protocol] Starting Coyote HTTP/1.1 on http-0.0.0.0-8080
15:46:51,343 INFO [ChannelSocket] JK: ajp13 listening on /0.0.0.0:8009
15:46:51,375 INFO [JkMain] Jk running ID=0 time=0/63 config=null
15:46:51,390 INFO [Server] JBoss (MX MicroKernel) [4.0.2 (build: CVSTag=JBoss_4_0_2 date=200505022023)] Started in 21s:500ms
5、跑数据库教本没出现错误
F而且,从jmx-cosole中startDatabaseManager可以看到已经存在的数据表,用SQL语句也可以读出数据
6、部署JBossDukesBank.ear没有出现error
7、打开http://localhost:8080/bank/main,用200/j2ee登陆出现错误:
6:03:50,703 INFO [STDOUT] Debug: Creating bean manager.
6:03:51,281 INFO [STDOUT] Debug: CustomerControllerBean ejbCreate
6:03:51,328 INFO [STDOUT] Debug: AccountControllerBean ejbCreate
6:03:51,359 INFO [STDOUT] Debug: TxControllerBean ejbCreate
6:03:51,390 INFO [STDOUT] Debug: /main
6:03:51,406 INFO [STDOUT] Debug: Forwarding to template.
6:03:53,812 INFO [STDOUT] Debug: AccountControllerBean getAccountsOfCustomer
6:03:53,890 INFO [STDOUT] Debug: AccountBean setEntityContext
6:03:53,890 INFO [STDOUT] Debug: AccountBean ejbFindByCustomerId
6:03:53,890 INFO [STDOUT] Debug: AccountBean selectByCustomerId
6:03:53,890 INFO [STDOUT] Debug: AccountBean makeConnection
6:03:53,890 INFO [STDOUT] Debug: AccountBean unsetEntityContext
6:03:53,906 ERROR [LogInterceptor] EJBException in method: public abstract java.util.Collection com.sun.ebank.ejb.account.Acc
untHome.findByCustomerId(java.lang.String) throws javax.ejb.FinderException:
avax.ejb.EJBException: ejbFindByCustomerId Unable to connect to database. Could not dereference object
at com.sun.ebank.ejb.account.AccountBean.ejbFindByCustomerId(AccountBean.java:181)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.jboss.ejb.plugins.BMPPersistenceManager.callFinderMethod(BMPPersistenceManager.java:615)
at org.jboss.ejb.plugins.BMPPersistenceManager.findEntities(BMPPersistenceManager.java:320)
at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.findEntities(CachedConnectionInterceptor.java:321)
.........
........
(错误是Unable to connect to database,源程序没有动过,连接数据库的为public static final String BANK_DATABASE = "java:comp/env/jdbc/BankDB";
我在hsqlds-ds中也将jndi-name改为jdbc/BankDB,为什么还是连接不上数据库。苦恼了很长时间,想必是自己那里配置的不对,劳驾高手指点。