A Java Servlet-jsp app running on on-premise hardware is to be migrated to pivotal cloud PaaS.
Currently, the app takes DB credentials from server.xml of Tomcat and the resource is added in the context.xml.
This is the context.xml
<ResourceLink name="jdbc/db"
global="jdbc/db"
auth="Container"
type="javax.sql.DataSource" />
This is server.xml
<Resource name="jdbc/db"
global="jdbc/db"
auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://HOST:3306/db"
username="..."
password="..."
maxActive="100"
maxIdle="20"
minIdle="5"
maxWait="10000"/>
How can I pass the Credentials to the server? Is there any standard way to pass DB credentials for PaaS applications?
Your Spring Boot application will be packaged as an executable JAR. It'll have an application.yml file inside it that contains your database connection credentials.
You can also configure your data source as a Pivotal Cloud Foundry service. That way the credentials are added to the cloud. Your app simply refers to them.
Related
After deploy mi javaweb (war) app, not maven, in heroku i get the next error:
https://imgur.com/a/KThbLxa
Obviusly it´s because is not making the connection to the JNDI
context.xml
<Resource name="jdbc/conexion" auth="Container" type="javax.sql.DataSource" maxActive="30"
maxIdle="10" maxWait="15000" username="XXXXXXXXX" password="XXXXXXXXXXX" driverClassName="com.mysql.cj.jdbc.Driver" url="jdbc:mysql://XXXXXXXXXX/XXXXXXXXXXXXXX"/>
So, somebody knows how includes a context.xml file in the deployed project?
I add to pom.xml tomcat embedded and his created in the target folder. I don't know how to configure jndi in tomcat, in target/tomcat/conf i don't have contex.xml when i manually created it and add
<Resource name="jdbc/MyDB"
global="jdbc/MyDB"
auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:#localhost:1521:orcl"
username="hr"
password="oracle"
maxActive="100"
maxIdle="20"
minIdle="5"
maxWait="10000"/>
and clean maven project everything disappear. Where to put configuration file in maven project and how to properly configure it.
I've been trying to configure a connection pool for a SQL Server 2012 database. I currently have Informix and Oracle pools configured and working, only SQL Server is giving me a headache. This is how my resource on Context.xml looks so far:
<Resource name="jdbc/sqlserv"
auth="Container"
factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
driverClass="com.microsoft.sqlserver.jdbc.SQLServerDriver"
type="javax.sql.DataSource"
maxActive="50"
maxIdle="10"
maxWait="15000"
username="username"
password="password"
url="jdbc:sqlserver://127.0.0.1:1433;databaseName=SQLDB;"
removeAbandoned="true"
removeAbandonedTimeout="30"
logAbandoned="true" />
That's using sqljdbc4 driver, of course. We already tried using jtds-1.3.0 with the driverClass="net.sourceforge.jtds.jdbc.Driver", but no go. All the resource-refs are also being correctly configured. Whenever I try to create a new connection using that Resource, it fails.
For comparison's sake, here's how our Informix and Oracle resources look like:
<Resource name="jdbc/infmx"
auth="Container"
type="javax.sql.DataSource"
factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
maxActive="50"
maxIdle="10"
maxWait="15000"
username="username"
password="password"
driverClassName="com.informix.jdbc.IfxDriver"
url="jdbc:informix-sqli://localhost:30091/infmx:informixserver=ol_infmx_soc"
removeAbandoned="true"
removeAbandonedTimeout="30"
logAbandoned="true"/>
<Resource name="jdbc/orcl"
auth="Container"
type="oracle.jdbc.pool.OracleDataSource"
driverClassName="oracle.jdbc.driver.OracleDriver"
factory="oracle.jdbc.pool.OracleDataSourceFactory"
url="jdbc:oracle:thin:#127.0.0.1:1521:orcl"
user="username"
password="password"
maxActive="50"
maxIdle="10"
maxWait="15000" />
So My question is: How can I correctly configure a connection pool for SQL Server 2012 on my tomcat context? I've searched high and low, attempted everything I've found, but nothing worked.
Thanks in advance.
[edit] Here's the stack trace: http://pastebin.com/w3rZSERs
[edit-2] It seems the problem is that Tomcat can't find the driver on his lib folder. We're pretty sure it's there, but we don't know to be sure of that. This happens with both sqljdbc4 and jtds-1.3.0. We're following every guideline we can find, but the problem persists.
We found our problem.
driverClass="com.microsoft.sqlserver.jdbc.SQLServerDriver"
Should have been
driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
It seems to me that the java side is correctly configured.
Can you access the server using another JDBC connection (for example SquirrelSQL or similar software)?
If you can't access to the server using Squirrel, maybe you did not enable the TCP/IP access to your server, in this case, follow the accepted answer of Enable remote connections for SQL Server Express 2012
On one developer workstation running Eclipse Helios SR2, Windows 7 and Tomcat 6.0.32 we have a very strange case of duplicate JNDI connection pools
Running tomcat from Eclipse
server.xml
>
<Context docBase="path to web app" path="/ds-web" reloadable="true">
<Resource
name="jdbc/ds"
username="ds"
password="pass"
type="javax.sql.DataSource"
url="jdbc:postgresql://localhost:5432/ds"
auth="Container"
driverClassName="org.postgresql.Driver"
factory="org.apache.commons.dbcp.BasicDataSourceFactory"
logAbandoned="true"
maxActive="30"
maxIdle="10"
maxWait="1000"
removeAbandoned="true"
removeAbandonedTimeout="60"
validationQuery="SELECT 1"
testOnBorrow="true"
testOnReturn="true"/>
</Context>
When start server, on the console we see the following 3 times in a row
AbandonedObjectPool is used
(org.apache.commons.dbcp.AbandonedObjectPool#11aa58b)
LogAbandoned: true
RemoveAbandoned: true
RemoveAbandonedTimeout: 60
Application then fails to find the JNDI resource
If we remove the <Resource> in server.xml, then the console shows no connection pool is created at all
On another developer machine with the same hardware and OS we do not have this problem
Any ideas?
Thanks
Marc
My suggestion, Copy the whole <Context> from server.xml and create a blank context.xml inside your web application META-INF folder and paste the <Context> copied from server.xml there.
Restart your application and see if this works.
We re-installed postgresql on the machine and the problem got solved somehow.
We're thinking something in the original postgresql config had been messed up and tomcat was failing to connect to the BD somehow. I guess tomcat was simply "trying 3 times", thus the triple output.
Another unsolved mystery...
move
<Resource
name="jdbc/ds"
username="ds"
password="pass"
type="javax.sql.DataSource"
url="jdbc:postgresql://localhost:5432/ds"
auth="Container"
driverClassName="org.postgresql.Driver"
factory="org.apache.commons.dbcp.BasicDataSourceFactory"
logAbandoned="true"
maxActive="30"
maxIdle="10"
maxWait="1000"
removeAbandoned="true"
removeAbandonedTimeout="60"
validationQuery="SELECT 1"
testOnBorrow="true"
testOnReturn="true"/>
to server.xml namely the
<GlobalNamingResources>
element
in your conf/context.xml file you would instead specify
<ContextLink name="jdbc/ds" global="jdbc/ds"/>
and this way, the three contexts will share the same pool.
How can we configure JNDI using tomcat server similar to JBoss server using jboss-web.xml?
Please help me on this?
I want to know which file we need to write it? or is there any programmatic way to do this?
Thanks in Advance,
Pravin
Write a context.xml
<Context>
<Resource name="jdbc/dbConnection"
auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="j<url to database>"
username="user"
password="pwdt"
validationQuery="select 1"
removeAbandoned="true"
removeAbandonedTimeout="120"
maxWait="60"
maxActive="20"
maxIdle="10" />
</Context>
Here's a JNDI HOWTO from Apache on how to configure JNDI on Tomcat 6.
Related topic.
If you want a JNDI data source or something else, read the docs. They are quite detailed.