0 Replies - 565 Views - Last Post: 19 September 2017 - 06:50 AM

#1 karengsh  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 132
  • Joined: 18-May 09

how to setup and resolve JNDI resources in Tomcat 8 ?

Posted 19 September 2017 - 06:50 AM

Hi expert,

I have been trying very hard for the past few weeks to get my connection via datasource but failed to get the connection going. :(

Here's the error I got :

Initial SessionFactory creation failed.org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
Sep 19, 2017 9:05:55 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [tutorController] in context with path [/Hi5S] threw exception [Servlet execution threw an exception] with root cause
javax.naming.NameNotFoundException: Name [hi5"/>] is not bound in this Context. Unable to find [hi5"].
	at org.apache.naming.NamingContext.lookup(NamingContext.java:818)
	at org.apache.naming.NamingContext.lookup(NamingContext.java:152)
	at org.apache.naming.NamingContext.lookup(NamingContext.java:829)
	at org.apache.naming.NamingContext.lookup(NamingContext.java:152)
	at org.apache.naming.NamingContext.lookup(NamingContext.java:829)
	at org.apache.naming.NamingContext.lookup(NamingContext.java:152)
	at org.apache.naming.NamingContext.lookup(NamingContext.java:829)
	at org.apache.naming.NamingContext.lookup(NamingContext.java:152)
	at org.apache.naming.SelectorContext.lookup(SelectorContext.java:134)
	at javax.naming.InitialContext.lookup(InitialContext.java:421)
	at org.hibernate.engine.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:97)
	at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.configure(DatasourceConnectionProviderImpl.java:98)



Here's my attempt :

My web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
  <display-name>Hi5S</display-name>
  <welcome-file-list>
    <welcome-file>Index.jsp</welcome-file>
  </welcome-file-list>
  <resource-ref>
    <description>MySQL Datasource</description>
    <res-ref-name>jdbc/hi5</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
  </resource-ref>
  <servlet>
    <servlet-name>tutorController</servlet-name>
    <servlet-class>controller.tutorController</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>tutorController</servlet-name>
    <url-pattern>/addTutor</url-pattern>
  </servlet-mapping>
</web-app>



my context.xml
<?xml version="1.0" encoding="UTF-8"?>

<Context>
	<Resource name="jdbc/hi5" 
	
	auth="Container" 
	type="javax.sql.DataSource"
	maxTotal="8" 
	maxActive="100" 
	maxIdle="30" 
	maxWait="-1"
	username="root"
	singleton="true" 
	factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
	password="root" 
	   alternateUsernameAllowed="true"
	driverClassName="com.mysql.jdbc.Driver" 
	url="jdbc:mysql://localhost:3306/hi5" />        
              
</Context>

and my persistence.xml

[code]
<?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="Hi5S" transaction-type="JTA" >	
	 <class>model.Subject</class>
		<class>model.Tutor</class>
	
     <properties>
     <!-- Configuring JDBC properties -->  
              <property name="hibernate.connection.datasource" value="java:comp/env/jdbc/hi5"/>  
      
	</properties>			
	</persistence-unit>
	
</persistence>




I hope someone can tell me where have I done wrongly or point me to any tutorial that can tell me the proper set up in Tomcat 8 in Eclipse. Tks.

Is This A Good Question/Topic? 0
  • +

Page 1 of 1