Connection Cast Exception Wildfly - wildfly

I am using Wildfly8 and postgresql as my DB. I need org.postgresql.PGConnection in order to implement LISTEN/NOTIFY functionality of postgresql.
My code looks like:
private Connection conn;
private org.postgresql.PGConnection pgconn;
Conn = entityManager.unwrap(java.sql.Connection.class);
this.pgconn = conn.unwrap(org.postgresql.PGConnection.class);
I get following Exception:
java.sql.SQLException: Not a wrapper for: org.postgresql.PGConnection
What can be the issue here?

It is possible that in this case your first instance of Connection is a Proxy Object. If you are using Wildfly you must do this:
((WrappedConnection)conn).getUnderlyingConnection().unwrap(PgConnection.class);
Also you must declare in the jboss-deployment-structure.xml something like this:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="org.jboss.ironjacamar.jdbcadapters" />
<module name="org.postgresql" />
</dependencies>
</deployment>
</jboss-deployment-structure>

Related

How to configure EJB/JPA in JTA transaction mode?

This is a simple guide for configuring JPA and connecting to your database using JTA transaction mode. Also it is including the most common mistakes that developers do and you should avoid them.
Hope this help you.
1- Set up a DataSource in your Application Server:
In order to configure JPA in your WebApp using JTA mode you need 1st setting up a DataSource. You can setup the DataSource from your Application Server (Glassfish / Payara / ...). but it is recommended to setup the Datasource through your Web App. Follow these steps to setup the DataSource for Glassfish or Payara through your Maven WebApp:
create a new folder (NOT Package) inside your project folder with name "setup".
create a new xml file and name it "glassfish-resources.xml" and save it inside "setup" folder.And write the bellow content:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
<jdbc-resource enabled="true" jndi-name="**jdbc/DBDev01**" object-type="user" pool-name="**jdbc/DBDev01-ConnectionPool**">
<description/>
</jdbc-resource>
<jdbc-connection-pool allow-non-component-callers="false"
associate-with-thread="false" connection-creation-retry-attempts="0"
connection-creation-retry-interval-in-seconds="10"
connection-leak-reclaim="false"
connection-leak-timeout-in-seconds="0"
connection-validation-method="auto-commit"
datasource-classname="**org.mariadb.jdbc.MariaDbDataSource**"
fail-all-connections="false"
idle-timeout-in-seconds="300"
is-connection-validation-required="false"
is-isolation-level-guaranteed="true"
lazy-connection-association="false"
lazy-connection-enlistment="false"
match-connections="false"
max-connection-usage-count="0"
max-pool-size="32"
max-wait-time-in-millis="60000"
name="**jdbc/DBDev01-ConnectionPool**"
non-transactional-connections="false"
pool-resize-quantity="2"
res-type="javax.sql.DataSource" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="false">
<!-- for MariaDB users, it recomended to add ?useMysqlMetadata=true, this will make MariaDB pretending that it is a MySQL for tools or libraries that not support MariaDB -->
<property name="URL" value="**jdbc:mariadb://XXX.XXX.XXX.XXX:XXXX/DB_NAME?useMysqlMetadata=true**"/>
<property name="User" value="**USERNAME**"/>
<property name="Password" value="**PASSWORD**"/>
</jdbc-connection-pool>
</resources>
Note: All values in between ** ** should be modified as per your settings.
This file will be loaded by your application server (Glassfish/Payara) after deploying your webapp. For Payara users you can also name the file with "payara-resources.xml" but with little modifications. Ref:Payara Deployment Descriptors.
2- Add Resource reference for the datasource in WEB-INF/web.xml:
you need to add a resource reference for the DataSource in your Webapp through adding this in WEB-INF/web.xml file:
<web-app .....>
......
<resource-ref>
<description>**DBDev01**</description>
<res-ref-name>**jdbc/DBDev01**</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<!-- <res-sharing-scope>Shareable</res-sharing-scope> -->
</resource-ref>
</web-app>
Note: The res-ref-name should match exactly the name you choose for the datasource in glassfish resources file.
3- Configure Persistence.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="**MyDB**" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<!-- List all Entity classes -->
<class>**com.MyEntityClassName**</class>
<jta-data-source>**jdbc/DBDev01**</jta-data-source>
<!-- you can list all entity classes you need and set this value to true. or set this value to false to include other entity clases -->
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<!-- while eclipselink not support MariaDB , set this property to enforce eclipselink to work with it as MySQL -->
<property name="eclipselink.target-database" value="MySQL"/>
</properties>
</persistence-unit>
</persistence>
Note 1: If you want to use JTA as transaction type, So you must defining jta-data-source. And it is a common mistake for developers adding DB URL,username and password in properties trying to connect to the database without defining the JTA data Source. This will not work and will lead your application server to use the default datasource that already defined which in common is an H2 database.
Note 2: eclipselink (JPA library) not supporting MariaDB. But there is a workarounds for that.
solution 1:: add "?useMysqlMetadata=true" as suffix on your connection URL Like: <property name="URL" value="**jdbc:mariadb://XXX.XXX.XXX.XXX:XXXX/DB_NAME?useMysqlMetadata=true"/> this will make MariaDB pretending that it is a MySQL.
solution 2: Enforce eclipselink to deal with the database as MySQL. this can be done by setting eclipselink.target-database property in persistence.xml as bellow:
<properties>
<!-- while eclipselink not support MariaDB , set this property to enforce eclipselink to work with it as MySQL -->
<property name="eclipselink.target-database" value="MySQL"/>
</properties>
4- Add JDBC client as Dependency in POM.xml:
<dependency>
<!-- This is for MariaDB. You should change it if you are using other kind of DB like MySQL or Oracle DB -->
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>2.7.2</version>
</dependency>
5- Enjoy with your Codes:
writing a sessionBean:
#Stateless
public class StudentManager
{
/* Notes:
1.you should use the same name exactly that defined in Persistence.xml file.
2.You can not use #PersistenceUnit with JTA. only use #PersistenceContext with JTA.
*/
#PersistenceContext(unitName="MyDB")
private EntityManager em;
public StudentManager()
{
}
public void persist(Student student) {
em.persist(student);
}
}
write TestController:
#Named
#SessionScoped
public class TestController
{
#Inject
private StudentManager studentManager;
private String message = "";
public void test()
{
Student student = new Student();
Student.setCode(11223344);
Student.setName("John");
studentManager.persist(Student);
/*Note:we used studentManager directly without constructing.
writing studentManager = new StudentManager() is a common mistake and will lead you to get a null EntityManager.*/
this.setMessage("A new Student already saved successful with Code:" + Student.getCode());
}
Common Question: Should use #Inject or #EJB? here is the answer
A simple JSF page for testing:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:form>
<h:commandButton value="Test Save a Student over JTA" action="#{testController.test()}" />
<br />
<h:outputLabel for="message" value="#{test.message}" />
</h:form>
</h:body>
</html>

wildfly wont start because of new missing/unsatisfied dependencies

When I try to start my WildFly server, I got this error :
2018-11-17 21:29:55,203 ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 33) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("jdbc-driver" => "org.postgresql")
]) - failure description: "WFLYJCA0041: Failed to load module for driver [org.postgresql]"
ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("data-source" => "swap")
]) - failure description: {"WFLYCTL0180: Services with missing/unavailable dependencies" => [
"jboss.driver-demander.java:jboss/datasources/swap is missing [jboss.jdbc-driver.org_postgresql]",
"jboss.data-source.java:jboss/datasources/swap is missing [jboss.jdbc-driver.org_postgresql]"
]}
2018-11-17 21:30:07,625 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("data-source" => "swap")
]) - failure description: {"WFLYCTL0180: Services with missing/unavailable dependencies" => [
"jboss.driver-demander.java:jboss/datasources/swap is missing [jboss.jdbc-driver.org_postgresql]",
"jboss.data-source.java:jboss/datasources/swap is missing [jboss.jdbc-driver.org_postgresql]",
"jboss.data-source.java:jboss/datasources/swap is missing [jboss.jdbc-driver.org_postgresql]"
]}
And my standalone.xml :
<datasources>
<datasource jndi-name="java:jboss/datasources/swap" pool-name="swap" enabled="true" use-java-context="true">
<connection-url>jdbc:postgresql://127.0.0.1:5432/swap?useUnicode=yes&characterEncoding=UTF-8</connection-url>
<driver>org.postgresql</driver>
<security>
<user-name>postgres</user-name>
<password>postgres</password>
</security>
</datasource>
<drivers>
<driver name="org.postgresql" module="org.postgresql">
<driver-class>org.postgresql.Driver</driver-class>
<xa-datasource-class>org.postgresql.Driver</xa-datasource-class>
</driver>
</drivers>
</datasources>
My PostgreSQL module.xml :
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.postgresql">
<resources>
<resource-root path="postgresql-42.2.5.jar"/>
</resources>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
What could be the problem? Please help and Thanks.
Your module.xml is invalid. A <dependencies> tag is missing. Try it with the following:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.postgresql">
<resources>
<resource-root path="postgresql-42.2.5.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
EDIT:
The module.xml file and the postgresql-42.2.5.jar have to be in
C:\wildfly\wildfly-9.0.2.Final\modules\system\layers\base\org\postgresql\main.
It is also recommended to put your modules directly into
C:\wildfly\wildfly-9.0.2.Final\modules\.
So in your case C:\wildfly\wildfly-9.0.2.Final\modules\org\postgresql\main, that can be problem.
For reference, also have a look at the EAP7 Documentation and you should also think about using the jboss-cli.
For configuration of PostgresSQL for WildFly server, you should follow the following steps.
Step 1 : Adding PostgreSQL Module
Create new folder ${wildfly_home}/modules/system/layers/base/org/postgresql/main/ if not exist.
Download Latest Driver Jar via this link => https://jdbc.postgresql.org/download.html and put under the above folder.
Also in that new folder, Create module.xml and put the following config.
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.3" name="org.postgresql">
<resources>
<resource-root path="postgresql-42.2.23.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
May be jar version need to update in resource-root.
Step 2 : Update DB configs from standalone.xml
Remove Existing <driver> config and add new config as follow.
<driver name="postgresql" module="org.postgresql">
<xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
</driver>
Remove existing <datasource> config and add new config as follow.
<datasource jndi-name="java:jboss/datasources/PostgresDS" pool-name="PostgresDS" enabled="true" use-java-context="true">
<connection-url>jdbc:postgresql://127.0.0.1:5432/swap?useUnicode=yes&characterEncoding=UTF-8</connection-url>
<driver>postgresql</driver>
<security>
<user-name>postgres</user-name>
<password>postgres</password>
</security>
<pool>
<max-pool-size>20</max-pool-size>
</pool>
</datasource>
Modify default-bindings datasource name to PostgresDS from ExampleDS.
<default-bindings context-service="java:jboss/ee/concurrency/context/default" datasource="java:jboss/datasources/PostgresDS" ...
Make sure that you have created your swap database in PostgreSQL database server.
Now, run server and it will be fine.

Wildfly 10 with Postgres 9.6.6 and Hibernate 5.2.12.final

I am trying to get a Java8EE application working on Wildfly10 and Postgres 9.6.6.
Somehow I allways bump into the error that the relation cannot be found.
My Postgres is running on localhost, default port. I am connecting with the user postgres and the correct password. The database (hbnac) has a schema with the same name.
Wildfly is configured to use the database and the “Test connection” is confirming a successful connection.
Using pgAdmin 4 I can also browse the database, see the schema, as well as the table group_member.
The config in Jboss looks as follow:
<datasource jta="false" jndi-name="java:jboss/datasources/hbnac" pool-name="hbnac" enabled="true" use-ccm="false">
<connection-url>jdbc:postgresql://localhost:5432/hbnac</connection-url>
<driver-class>org.postgresql.Driver</driver-class>
<driver>postgres</driver>
<pool>
<min-pool-size>1</min-pool-size>
<initial-pool-size>1</initial-pool-size>
<max-pool-size>10</max-pool-size>
<flush-strategy>Gracefully</flush-strategy>
</pool>
<security>
<user-name>postgres</user-name>
<password>password</password>
</security>
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker"/>
<background-validation>true</background-validation>
<exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter"/>
</validation>
</datasource>
However, my application fails to select a record from the very same table, resulting in the following error:
Caused by: org.postgresql.util.PSQLException: ERROR: relation "group_member" does not exist
The configuration of my persistence.xml is doing a jndi lookup of the connection defined in Wildfly:
<persistence-unit name="hbnac">
<jta-data-source>java:jboss/datasources/hbnac</jta-data-source>
<class>hbnac.birthday.domain.groupmember.GroupMember</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL94Dialect" />
<!--property name="hibernate.hbm2ddl.auto" value="validate"/-->
<!--property name="hibernate.default_schema" value="hbnac"/-->
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true" />
</properties>
</persistence-unit>
And obviously, the jta-data-source is matching the working datasource in Wildfly. As you can see, I have experimented a bit with the validate (which fails for the same reason at startup) and with the schema name, which also does not make a difference.
The entity itsel is annoted:
#Entity
#Table(name = "group_member")
public class GroupMember extends AbstractEntity {
public final static String FACEBOOK_NAME_FIELD = "facebookName";
public final static String BIRTHDAY_FIELD = "birthday";
#Id
#GeneratedValue(strategy= GenerationType.IDENTITY)
private long id;
It has getters, setters, hashcode and equals methode for all fields available.
If I copy the query generated by hibernate into pgadmin it also works perfectly...
Any ideas left?
success to test connection, but even couldn't find table
that indicates ,perhaps schema setting is not defined correctly.
then, should put a currentSchema like this
<connection-url>jdbc:postgresql://localhost:5432/hbnac?currentSchema=hbnac</connection-url>
and if you use Hibernate to issue query should enable this comment outed code
<!--property name="hibernate.default_schema" value="hbnac"/-->
I found the error after many tries! It was caused by the configuration of the Postgres module in Wildfly itself.
What I had before:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.postgres">
<resources>
<resource-root path="postgresql-42.1.4.jar" />
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.servlet.api" optional="true" />
</dependencies>
and in the standalone.xml:
<driver name="postgres" module="org.postgres">
<xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
<datasource-class>org.postgresql.ds.PGSimpleDataSource</datasource-class>
</driver>
for the datasource itself:
<datasource jta="false" jndi-name="java:jboss/datasources/hbnac" pool-name="hbnac" enabled="true" use-ccm="false">
<connection-url>jdbc:postgresql://localhost:5432/hbnac</connection-url>
<driver-class>org.postgresql.Driver</driver-class>
<driver>postgres</driver>
...
This configuration gave a successful connection but the error that a relation could not be found.
By replacing it with the following configuration, everything is working fine:
For the module.xml:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.postgres">
<resources>
<resource-root path="postgresql-42.1.4.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.servlet.api" optional="true"/>
</dependencies>
For the driver in the standalone.xml:
<driver name="postgresql" module="org.postgres">
<driver-class>org.postgresql.Driver</driver-class>
</driver>
And finally for the db connection:
<datasource jta="true" jndi-name="java:/PostgresDS" pool-name="PostgresDS" enabled="true" use-java-context="true">
<connection-url>jdbc:postgresql://localhost:5432/hbnac</connection-url>
<driver>postgresql</driver>
<security>
...

Can't create EntityManager using JTA Datasource

I'm trying to instantiate an EntityManager using a JTA Datasource, but I always get NullPointerException.
Here's my environment:
Server : JBossAS 7.0
JPA : 2.0
DB : MySQL
persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="WebStock" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>stockmanagementDS</jta-data-source>
<class>prv.stockmanagement.business.Product</class>
</persistence-unit>
</persistence>
On a dao class I'm trying this :
#PersistenceContext(type=PersistenceContextType.EXTENDED, unitName="WebStock")
private EntityManager em;
but when I use its getter, I get NullPointerException here :
public EntityManager getEntityManager() {
return em;
}
the debug shows it's null.
Here's the datasource definition in the standalone.xml :
<datasource jndi-name="stockmanagementDS" pool-name="stockmanagement" enabled="true" jta="true" use-java-context="true" use-ccm="true">
<connection-url>
jdbc:mysql://localhost:3306/kitchen_stock
</connection-url>
<driver>
mysql
</driver>
<security>
<user-name>
root
</user-name>
<password>
rootroot
</password>
</security>
<statement>
<prepared-statement-cache-size>
100
</prepared-statement-cache-size>
<share-prepared-statements/>
</statement>
</datasource>
"mysql" is the name of the driver I defined after the datasource :
<drivers>
<driver name="mysql" module="com.sql.mysql">
<driver-class>
com.mysql.jdbc.Driver
</driver-class>
</driver>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>
org.h2.jdbcx.JdbcDataSource
</xa-datasource-class>
</driver>
</drivers>
Persistence is under META-INF, it's dynamic web project, and it's working well. The classing using the entity manager is not an EJB.
Any hint?
Let me draw your attention to the following moments:
1. I don't see in your code driver for MySql to which you refer from datasource:
<driver>
mysql
</driver>
You mast do follow:
Enter in the file path ${jboss_home}/modules and create the directories com/mysql/jdbc/main. Into the folder main copy the driver library jar (for example mysql-connector-java-5.1.38-bin.jar) and create a file module.xml:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="com.mysql.jdbc">
<resources>
<resource-root path="mysql-connector-java-5.1.38-bin.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
</dependencies>
</module>
And to the <drivers> tag in the standalone.xml add:
<driver name="mysql" module="com.mysql.jdbc">
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>
2. May be you should put your persistence.xml in your web module:
web
src
main
java
..
resources
META-INF
persistence.xml
webapp
..
3. You can do inject EntiryManeger only into EJB or class with #Transactional annotation. Check to be sure your DAO class it is EJB bean.

JNDI lookup of a datasource in JBoss 7.0.2 resulting in a NameNotFoundException

I'm having some issues getting a JNDI lookup of a datasource in JBoss 7.0.2 to work properly. Basically, this application is one that should be deployable across multiple application servers, so I'd like to adhere to appropriate standards. The application in question is a simple portlet application deployed in Liferay 6.1 running in a Jboss managed domain; I've tried various combinations of naming conventions in web.xml, jboss-web.xml, and persistence.xml; all to no avail. My current configuration looks like this:
Spring persistence.xml:
<jee:jndi-lookup id="surveyDS" jndi-name="jdbc/surveyDS" resource-ref="true" />
web.xml:
<?xml version="1.0"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_4.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_4.xsd" id="WebApp_ID" version="2.4">
...
<resource-ref>
<res-ref-name>jdbc/surveyDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
</web-app>
jboss-web.xml:
<?xml version="1.0"?>
<!DOCTYPE jboss-web PUBLIC "-//JBoss//DTD Web Application 2.4//EN" "http://www.jboss.org/j2ee/dtd/jboss-web_4_0.dtd">
<jboss-web>
<resource-ref>
<res-ref-name>jdbc/surveyDS</res-ref-name>
<jndi-name>java:jboss/datasources/surveyDS</jndi-name>
</resource-ref>
</jboss-web>
Datasource definition in ${JBOSS_HOME}/domain/configuration/domain.xml:
<datasource jndi-name="java:jboss/datasources/surveyDS" pool-name="TestDSPool" enabled="true" jta="true" use-java-context="true" use-ccm="true">
<connection-url>****</connection-url>
<driver>com.mysql</driver>
<pool>
<prefill>false</prefill>
<use-strict-min>false</use-strict-min>
<flush-strategy>FailingConnectionOnly</flush-strategy>
</pool>
<security>
<user-name>****</user-name>
<password>****</password>
</security>
</datasource>
Deploying the portlet application works just fine; however, when I attempt to actually view the portlet, I get the following exception:
15:10:05,493 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/survey-portlets].[surveydisplay Servlet]] (ajp--0.0.0.0-8009-3) Servlet.service() for servlet surveydisplay Servlet threw exception: javax.naming.NameNotFoundException: jdbc/surveyDS -- service jboss.naming.context.java.jdbc.surveyDS
at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:87)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:173)
at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:47)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:209)
at javax.naming.InitialContext.lookup(InitialContext.java:392) [:1.6.0_26]
at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:154) [org.springframework.context-3.0.5.RELEASE.jar:]
at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87) [org.springframework.context-3.0.5.RELEASE.jar:]
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152) [org.springframework.context-3.0.5.RELEASE.jar:]
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178) [org.springframework.context-3.0.5.RELEASE.jar:]
at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:104) [org.springframework.context-3.0.5.RELEASE.jar:]
at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105) [org.springframework.context-3.0.5.RELEASE.jar:]
at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:201) [org.springframework.context-3.0.5.RELEASE.jar:]
at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:187) [org.springframework.context-3.0.5.RELEASE.jar:]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477) [org.springframework.beans-3.0.5.RELEASE.jar:]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417) [org.springframework.beans-3.0.5.RELEASE.jar:]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) [org.springframework.beans-3.0.5.RELEASE.jar:]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) [org.springframework.beans-3.0.5.RELEASE.jar:]
[ ... stack truncated for brevity ]
I feel like I must be missing something very simple and obvious at this point, but I have no idea what it might be. Any suggestions would be greatly appreciated!
Change the DataSource jndi-name in the JBoss domain.xml file to java:jdbc/surveyDS, and you should be fine.