Can I set Tomcat's JNDI connection pooling settings in my Spring-MyBatis application? - spring

Environment:
Tomcat 7
JNDI
Spring-MyBatis
No JTA - commons pooling only
Problem: Can't get the connection pooling to work as advertised. I can't find a single example of this that doesn't use a stand-alone Transaction manager or that doesn't put all the settings in the war, which makes JNDI pointless. I'm told that JTA is overkill for this application and that we should stick with commons pooling. That makes sense but I don't see a way to configure pooling, if we do it that way.
So... how do I configure connection pooling without putting the settings in the war file AND without using a stand-alone transaction manager? Can this be done without a full Java EE Application Server? We are just moving to Tomcat from another product which actually is full Java EE, so I am thinking this may be a Container vrs. Application server issue.
The weird part is that we can and have used JNDI but the pooling is definitely wrong.
Here is one example that probably works but why bother with JNDI if the settings are going to be in META-INF/context.xml?:
MyBatis JNDI Example

Even with context.xml, it's still a container level setting. But, it's a convenient way of deploying everything in a singe unit rather than having to create the connection pool before you deploy the WAR file.
JNDI is meant to keep your application configuration generic. If you take your WAR and deploy it in WebSphere, for example, it will ignore the context.xml file. But WebSphere will see that you have a JDNI resource-ref in your web.xml and walk you through creating the data source. Same idea as Tomcat, just a different way of doing it.
If you are 100% sure that this application will only run in Tomcat then you don't have to use JNDI. But, it will save you trouble later if you do move to another container.

Related

Embedded ActiveMQ Server within Tomcat 8

I am trying to embed ActiveMQ Server within Tomcat 8 server.
For that I was following two tutorials available online.
https://isomorphic.atlassian.net/wiki/display/Main/Real-Time+Messaging+with+Tomcat+and+ActiveMQ
and
http://www.tomcatexpert.com/blog/2010/12/20/integrating-activemq-tomcat-using-global-jndi
In first tutorial changes were made only in $TomcatHome/conf/context.xml. But in second tutorial it was recommended to modify context.xml, server.xml and activemq.xml.
I follows both the tutorial separately one by one, also tried to use these with "Tomcat 7". But looks like both are not working for me.
With these changes, tomcat server starts without any issue no error in log. But Embedded ActiveMQ BrokerService is not getting started with Tomcat. Nothing is there in startup log for BrokerService.
Means there is no effect of these configurations on Tomcat Serve, and startup log is same with or without these configuration.
Am I missing anything in configuration for Tomcat 7 or Tomcat 8?
Why new JNDI Resource TAGs in configuration files is not getting picked by Tomcat?
Guys please help me.
I suggest looking at starting up ActiveMQ using the Spring XML bean configuration. Generally, you'll need/want to do some configuration of the broker and having the full XML is a simple way to manage that. I suggest looking at creating a simple war file that starts up a Spring beans.xml file. That file should just be the same contents as the conf/activemq.xml configuration. You then add all the JNDI resources as needed to point to the embedded broker.

Arquillian JMS embedded

Seen examples (very few) of setting up Arquillian to test jms with remote profiles. Is it possible to test against an embedded container. Doesn't matter right now what the embedded implementation is (i.e. tomee, wildfly etc.). Would love a link or tip how to set this up via ShrinkWrap and an embedded configuration.
It works with tomee (embedded, remote) and openejb (really embedded ;)). Conf looks like properties of this file: http://svn.apache.org/repos/asf/tomee/tomee/trunk/arquillian/arquillian-tomee-tests/arquillian-tomee-jms-tests/src/test/resources/arquillian.xml, basically tomee/openejb properties to define a broker, queue etc...see http://tomee.apache.org/containers-and-resources.html for details

How to specify JDBC setting in a struts project?

I am trying to setup a struts project locally. One way I know to set up JDBC settings as to go to administrative console of websphere and create JDBC provider and JNDI and all. But is there any other way to do in the code itself?
There is some resource reference in web.xml. I am totally new to struts.Please help.
DataSourceAlias
javaxsql.Data...... etc etc
If you configured for WAS 6.1and configuration is good you need to stop and start nodeAgents for the changes to get propagated and test the jdbc connection after restarting.....if it was WAS 8 they will be propagated automatically that means you configured improperly

What datasource to use instead of jboss one's?

we are removing jboss from spring-based application and considering what a datasource to use instead of jboss's one for oracle. We used such properties (in oracle-ds.xml) as
min-pool-size
max-pool-size
blocking-timeout-millis
prepared-statement-cache-size
etc...
didn't find analog params in BasicDataSource, apache connection pool.
Have a look at c3p0. It should fit your needs. Here are the configuration details.

How do I declare a data source for GlassFish?

I know how I'd do this using JBoss: create a *-ds.xml file, and drop it into my deploy directory.
Is there a declarative way to do the same with GlassFish (v3.1)?
Am I thinking about this the wrong way? (See next question)
Is there a more-Glassfishy way to get my Java EE application to talk to a database?
Other potentially-revelant info:
I want to connect to a SQL Server 2008 database
I'm using Eclipse + GlassFish Server Tools
I know next to nothing about GlassFish. I'm much more familiar with JBoss
You can define it in application.xml or ejb-jar.xml of your EAR. You can even use annotations.
Long answer short: DataSource Resource Definition in Java EE 6.
BalusC is right (+1), with Java EE 6 you can declare datasource definitions either through annotations or through the use of deployment descriptors in a standard and portable way.
Just in case you'd be also interested by creating other resources than datasources like JMS resources, you can also package a glassfish-resources.xml file as part of your application. See:
Supporting glassfish-resources.xml
4.1.3 Application scoped resources

Resources