This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Hands On Software Engineering with Python and have Brian Allbey on-line!
See this thread for details.
Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

datasource using tomcat in spring  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to use datasource using tomcat in spring
i created spring

<bean id="dataSource"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>bookDataSource</value>
</property>
</bean>


this is my server.xml file

<?xml version="1.0" encoding="UTF-8"?>
<Server>
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
<Listener className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/>
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"/>
<GlobalNamingResources>
<Environment
name="simpleValue"
type="java.lang.Integer"
value="30"/>
<Resource
auth="Container"
description="User database that can be updated and saved"
name="UserDatabase"
type="org.apache.catalina.UserDatabase"
pathname="conf/tomcat-users.xml"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"/>
<Resource
name="bookDataSource"
type="javax.sql.DataSource"
password="admin"
driverClassName="com.mysql.jdbc.Driver"
maxIdle="2"
maxWait="5000"
validationQuery="select * from book"
username="root"
url="jdbc:mysql://localhost:3306/hibernate?autoReconnect=true "
maxActive="4"/>


</GlobalNamingResources>


<Context path="/bookDataSource" docBase="bookDataSource" debug="0"
reloadable="true" crossContext="true">


<Resource name="bookDataSource" auth="Container"
type="javax.sql.DataSource"/>
<ResourceParams name="bookDataSource">
<parameter><name>username</name><value>root</value></parameter>
<parameter><name>password</name><value>admin</value></parameter>
<parameter><name>driverClassName</name>
<value>com.mysql.jdbc.Driver</value></parameter>
<parameter><name>url</name>
<value>jdbc:mysql://localhost:3306/hibernate?autoReconnect=true</value></parameter>
</ResourceParams>

</Context>

<Service
name="Catalina">
<Connector
port="8080"
redirectPort="8443">
</Connector>
<Connector
port="8009"
protocol="AJP/1.3"
protocolHandlerClassName="org.apache.jk.server.JkCoyoteHandler"
redirectPort="8443">
</Connector>
<Engine
defaultHost="localhost"
name="Catalina">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"/>
<Host
appBase="webapps"
name="localhost">

</Host>
</Engine>
</Service>
</Server>



this my web.xml file

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>
springbook</display-name>
<servlet>
<description>
</description>
<display-name>
bookservlet</display-name>
<servlet-name>bookservlet</servlet-name>
<servlet-class>book.bookservlet</servlet-class>
</servlet>
<servlet>
<description>
</description>
<display-name>
programServlet</display-name>
<servlet-name>programServlet</servlet-name>
<servlet-class>
book1.programServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>bookservlet</servlet-name>
<url-pattern>/bookservlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>programServlet</servlet-name>
<url-pattern>/programServlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>

<resource-ref>
<description>DB Connection</description>
<res-ref-name>bookDataSource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

</web-app>


but error comes
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is javax.naming.NameNotFoundException: Name DataSource is not bound in this Context

how to solve this
 
Marshal
Posts: 67193
169
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"karthik jk", you have previously been warned on multiple occasions regarding adjusting your display name to meet JavaRanch standards. This is not optional, and this is your final warning. Adjust your display name to comply with the required standards prior to your next post.

Failure to comply will result in the removal of your account.

bear
JavaRanch Sheriff
 
My honeysuckle is blooming this year! Now to fertilize this tiny ad:
Programmatically Create PDF Using Free Spire.PDF with Java
https://coderanch.com/wiki/703735/Programmatically-Create-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!