在使用JBoss AS5中遇到的问题记录

1、web容器改默认端口为自定义端口
在D:/jboss-5.1.0.GA/server/default/deploy/jboss/web.sar/server.xml
找到
<Connector protocol=”HTTP/1.1″ port=”8080″ address=”${jboss.bind.address}” connectionTimeout=”20000″ redirectPort=”8443″ />
port=”8080″改为自定义端口
2、让非本机的局域网地址访问web容器
默认ip绑定的只能通过127.0.0.1:8080/来访问。
修改D:jboss-5.1.0.GAbinrun.bat
找到-Djava.endorsed.dirs=”%JBOSS_ENDORSED_DIRS%” ^
在上边加一行
-Djboss.bind.address=0.0.0.0 ^
变为如下
:RESTART
“%JAVA%” %JAVA_OPTS% ^
-Djboss.bind.address=0.0.0.0 ^
-Djava.endorsed.dirs=”%JBOSS_ENDORSED_DIRS%” ^
-classpath “%JBOSS_CLASSPATH%” ^
org.jboss.Main %*

3、包隔离发布
在xxx.warWEB-INF目录下新增jboss-web.xml
内容如下

<!DOCTYPE jboss-web PUBLIC "-//JBoss//DTD Web Application 5.0//EN"
"http://www.jboss.org/j2ee/dtd/jboss-web_5_0.dtd">
<jboss-web>

<class-loading java2ClassLoadingCompliance='true'>
<loader-repository>com.footmarktech:archive=helloworld-0.0.1
<loader-repository-config>java2ParentDelegaton=true</loader-repository-config>
</loader-repository>
</class-loading>

<context-root>helloworld</context-root>
</jboss-web>

4、中文乱码
在D:jboss-5.1.0.GAserverdefaultdeployjbossweb.sarserver.xml
找到
<Connector protocol=”HTTP/1.1″ port=”8080″ address=”${jboss.bind.address}” connectionTimeout=”20000″ redirectPort=”8443″ />
增加attribute URIEncoding=’UTF-8′
变成<Connector protocol=”HTTP/1.1″ port=”8080″ address=”${jboss.bind.address}” connectionTimeout=”20000″ redirectPort=”8443″ attribute URIEncoding=’UTF-8’/>
5、jboss5部署数据源
1)把mysql的jdbc驱动包mysql-connector-java-5.1.7-bin.jar放进D:\jboss-5.1.0.GA\server\default\lib中
2)D:\jboss-5.1.0.GA\server\default\deploy中新增一个文件名为mysql-ds.xml
内容如下

<?xml version="1.0" encoding="UTF-8"?>
<datasources>
<local-tx-datasource>
<jndi-name>MySqlDS</jndi-name>
<connection-url>jdbc:mysql://127.0.0.1:3306/mytest?user=root&amp;password=root&amp;useUnicode=true&amp;characterEncoding=UTF-8&amp;characterSetResults=UTF-8</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<user-name>root</user-name>
<password>root</password>
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
<!-- should only be used on drivers after 3.22.1 with "ping" support
<valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLValidConnectionChecker</valid-connection-checker-class-name>
-->
<!-- sql to call when connection is created
<new-connection-sql>some arbitrary sql</new-connection-sql>
-->
<!-- sql to call on an existing pooled connection when it is obtained from pool - MySQLValidConnectionChecker is preferred for newer drivers
<check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
-->

<!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
<!--
<metadata>
<type-mapping>mySQL</type-mapping>
</metadata>-->
</local-tx-datasource>
</datasources>

3)使用spring获取数据源

<bean id=”dataSource”>
<property name=”jndiName”><value>java:/MySqlDS</value></property>
<property name=”resourceRef”><value>false</value></property>
<property name=”jndiEnvironment”>
<props>
<prop key=”java.naming.provider.url”>jnp://localhost:1099</prop>
<prop key=”java.naming.factory.initial”>org.jnp.interfaces.NamingContextFactory</prop>
</props>
</property>
</bean>
4)错误
错误1

2010-06-21 06:46:16,934 WARN  [org.jboss.resource.connectionmanager.JBossManagedConnectionPool] (main) Throwable while attempting to get a new connection: null
org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (org.jboss.resource.JBossResourceException: Apparently wrong driver class specified for URL: class: com.mysql.jdbc.Driver, url: jdbc:mysql://127.0.0.1:3306/mytest?user=root&password=root&useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8)
at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.getLocalManagedConnection(LocalManagedConnectionFactory.java:225)
at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.java:195)

由于mysqljdbc驱动包没有被提前加载,将mysqljdbc驱动放到server/default/lib下即可

错误2

Caused by: javax.xml.bind.UnmarshalException
- with linked exception:
[org.xml.sax.SAXParseException: The reference to entity "password" must end with the ';' delimiter.]
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.createUnmarshalException(AbstractUnmarshallerImpl.java:315)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.createUnmarshalException(UnmarshallerImpl.java:514)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:215)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:190)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:238)
at org.jboss.resource.deployers.ManagedConnectionFactoryParserDeployer.parse(ManagedConnectionFactoryParserDeployer.java:123)
at org.jboss.resource.deployers.ManagedConnectionFactoryParserDeployer.parse(ManagedConnectionFactoryParserDeployer.java:63)
at org.jboss.deployers.vfs.spi.deployer.AbstractVFSParsingDeployer.parseAndInit(AbstractVFSParsingDeployer.java:256)
at org.jboss.deployers.vfs.spi.deployer.AbstractVFSParsingDeployer.parse(AbstractVFSParsingDeployer.java:239)
at org.jboss.deployers.spi.deployer.helpers.AbstractParsingDeployerWithOutput.createMetaData(AbstractParsingDeployerWithOutput.java:355)
... 33 more
Caused by: org.xml.sax.SAXParseException: The reference to entity "password" must end with the ';' delimiter.

jdbc驱动链接书写不正确
jdbc:mysql://127.0.0.1:3306/mytest?user=root&password=root&useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8
jdbc:mysql://127.0.0.1:3306/mytest?user=root&amp;password=root&amp;useUnicode=true&amp;characterEncoding=UTF-8&amp;characterSetResults=UTF-8

原创文章,转载请注明: 转载自海波无痕

本文链接地址: 在使用JBoss AS5中遇到的问题记录

文章的脚注信息由WordPress的wp-posturl插件自动生成

此条目发表在javaee, spring分类目录,贴了, , 标签。将固定链接加入收藏夹。