JBoss 7 Spring Oracle connection pooling - oracle

I want to use Spring framework to create application that uses Oracle 11g to store data.
Can you tell me how to configure the Spring framework to use the connection pooling with JBoss 7 and Oracle 11g.
Is it possible to put this code onto OSGI bundle?

You have to configure your datascource in JBoss first. After configuring your datasource it should hava a JNDI name like "jdbc/yourDataSource".
You can now reference this datasource from your spring context.
<jee:jndi-lookup id="dataSource" jndi-name="jdbc/yourDataSource"/>
Have a look at the documentation
If you use relative JNDI names then you have to put additional settings into the web.xml. For global nameing set resource-ref="false". For Spring it should not matter what database you use as its managed by the application server.
I cannot tell you if you can use it in a OSGI bundle.

Related

Spring boot datasource specific properties for embedded jetty server

I have spring boot application and it's basically a gradle project, so, I have below dependency added in my gradle file:
org.springframework.boot:spring-boot-gradle-plugin:1.5.1.RELEASE
Application gets deployed in embedded jetty server. I have following set of properties in application.properties for db connection polling:
spring.datasource.driver-class-name
spring.datasource.max-active
spring.datasource.max-idle
spring.datasource.min-idle
spring.datasource.validation-query
spring.datasource.name
I was referring to below two links:
https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-1.4-Configuration-Changelog
https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-1.5-Configuration-Changelog
I came to know that some of the datasource properties which used in application.properties file in my application are removed starting sprint boot version 1.4 but issue they haven't mentioned what are the new properties to use. Like for tomcat server they have provided all set of properties but not for jetty server. I am facing some db related errors like 'too many connections' after my application run for sometime, my assumption is that datasource props I am currently using are not correct and should be replaced with correct values, but unfortunately I am unable to find correct property names.
Jetty doesn't have its own Pooling DataSource implementation. You can include HikariCP in your project and customise using the spring.datasource.hikari.* properties. With each property matching the bean properties that can be set on Hikari's datasource implementation.

Alternative of JTATransaction

I have an Spring based J2EE application which runs well on Weblogic, I wanted to move it to Tomcat.
It seems tomcat doesn't support JTA Transaction Manager without external jar help like Atomikos, JOTM, Bitronix, SimpleJTA.
I am reluctant to make changes into my application where i am already using annotation based JTA transaction manager.
Are there alternatives for JTA Transaction Manager which I can use so that I am able to switch from weblogic to tomcat or tomcat to weblogic or any other server without changing my configuration file each time?
All in all what's best for transaction manager configuration when you want to keep your application (war) independent of server(s).
You could try TomEE.
It's a Java EE 6 server that meets the Web Profile requirements and is based on Tomcat.
So it will support JTA transactions.
You can get it from http://tomitribe.com
Just to give you a more direct link to TomEE: http://tomee.apache.org/download/tomee-1.7.2.html
If your application is configured and developed to use Weblogic then chances are you are using JDNDI to lookup the JTA transaction manager and your datasources.
So any solution that supports the same lookups would work.
For Atomikos, we recently added (commercial) support for Tomcat's JNDI space - check out http://www.atomikos.com/Main/BuyOnline to learn more.
Hope this helps!

Migrating database in spring application

In spring integrated hibernated application,I need to change the database from sql server to oracle without code change ?
If you really just want to change the datasource
have a look at the documentation here Spring Documentation for Oracle JDBC
You need to change your datasource that you use to point to Oracle.
Import the JDBC dependency for the Oracle JDBC connector as a dependency
Configure Hibernate to use the correct dialect
e.g. oracle.jdbc.driver.OracleDriver
Don't know how you configure your environment, but that should get you started.

Spring configuration to call different database environments like dev,int,uat,prod

I am having a Java standalone application, which is using the Spring core container and spring jdbc. I have different database environments like dev,int,uat,prod. These database configuration details and datasources for each environments are configured in spring configuration file spring-beans.xml along with the DAO beans.
Now i have to update the application, like if i passed a particular the database environment(like dev,int,uat,prod) as arguments at the time of running the application, the application will invoke the database as mentioned in the arguments. is there any way out?
i think you should used spring with hibernate it much easier or you can use JDNI for that
db1Jndi=
jdbc.url=jdbc:mysql://localhost:3306/db1
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.username=root
jdbc.password=root
db2Jndi=
jdbc.url=jdbc:mysql://localhost:3306/db2
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.username=root
jdbc.password=root

Difference between a Spring datasource and a Tomcat datasource?

What is the difference between a Spring datasource and Tomcat datasource? Any pro's / con's? Is there a favored choice?
When using a Tomcat datasource you have to drop the JDBC driver JAR file(s) in Tomcat's classpath (the Tomcat/lib). This is sometimes not affordable/possible, for example when it concerns 3rd party hosting with zero server admin rights. When using a Spring managed datasource, it's sufficient to just drop the JDBC driver JAR file(s) in webapp's classpath (the Webapp/WEB-INF/lib). Plus, I'd imagine that you've in Spring the additional benefit that you don't need to grab the DataSource manually. Also, you have the freedom of choosing a specific connection pool. Also, Tomcat ships with DBCP builtin as default connection pool which is not the best choice per se. With Spring, you could for example choose BoneCP above DBCP without the need to fiddle with Tomcat default configuration/classpath.
If you have a datasource in the Spring config, you associate it with a Tomcat datasource when you are in a web application. You can associate it with something else, for example Spring DriverManagerDataSource when you run unit tests.

Resources