我正在尝试获取我在JBoss 7.1上的GateIn 3.2.0中部署的portlet中的数据源。
首先,我在standalone.xml中创建了数据源
<datasource jta="true" jndi-name="java:jboss/datasources/ccr" pool-name="ccr-pool" enabled="true" use-java-context="false" use-ccm="true">
<connection-url>jdbc:mysql://localhost:42006/contentrepository</connection-url>
<driver>com.mysql</driver>
<security>
<user-name>node</user-name>
</security>
<statement>
<prepared-statement-cache-size>100</prepared-statement-cache-size>
<share-prepared-statements>true</share-prepared-statements>
</statement>
</datasource>我还添加了驱动程序和驱动程序的模块。
在我的portlet中,我尝试使用以下命令访问数据源
dataSource = (DataSource) new InitialContext().lookup("java:jboss/datasources/ccr");但是我只得到了一个javax.naming.NameNotFoundException:在上下文'‘中找不到的名字'jboss’。
我还尝试用以下命令获取它:
dataSource = (DataSource) new InitialContext().lookup("java:comp/env/datasources/ccr");并将其与web.xml和jboss-web.xml中的以下条目进行映射
web.xml:
<resource-ref>
<description>MySQL DS</description>
<res-ref-name>datasources/ccr</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>jboss-web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
<resource-ref>
<res-ref-name>datasources/ccr</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<jndi-name>java:jboss/datasources/ccr</jndi-name>
</resource-ref>
</jboss-web>然后我得到了javax.naming.NameNotFoundException:在上下文'‘中找不到的名称'comp’。
我遗漏了什么?是否有一些安全设置阻止我的应用程序获取数据源?
奇怪的是,在使用servlet时,我可以在同一个when应用程序中获取数据源,但只能在doGet/doPost方法中获取,而不能在init()中获取。
发布于 2012-08-23 04:07:13
我在GateIn 3.3上也遇到了同样的问题。但它不能用GateIn 3.4M1重现。当我在谷歌上搜索这个bug时,我在JIRA中找到了它:https://issues.jboss.org/browse/GTNPORTAL-2511
https://stackoverflow.com/questions/10717454
复制相似问题