Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!

Ranban Smith

Greenhorn
+ Follow
since Aug 18, 2011
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Ranban Smith

Hi,
I am working on a tomcat application, in which there is a Spring bean which is declared like

<bean name="PleskXMLInputs" class="<FULLY_QUALIFIED_CLASS_NAME>"
depends-on="registered_shared_ServiceLayersCache">
<property name="slCacheIdentifier" ref="..."/>
</bean>

The xml files containing the declarations are declares included in the web.xml, as follows:

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:/spring_context.xml
</param-value>
</context-param>

Now the above mentioned bean is used somewhere in the web application. The class does not extend servlet, so I can't use the getServletContext() approach. Is there any way I can read a properties file placed somewhere inside the web application (WEB-INF,WEB-INF/classes, META-INF - anywhere is fine) from inside the bean class?
6 years ago
Hello all,
This is my first post here. Not sure if it belongs to the servlets or the tomcat subforum.

Some background first -
I am using a database pooling framework called primrose. Among other things, it contains a web console, using which one may view the statuses and statistics about database connections. The console works as follows - an ObjectFactory implementor is provided, and the webconsole needs to be declared as a resource. The factory starts a (non daemon) thread in the background, and starts listening for connections on some port. To shut down the web console, a servlet class in the Primrose code needs to be declared in web.xml, and this servlet shuts down the web console, among other things.

Some questions:
1. AFAIK, the resource can be declared in the application's context, as well as in the GlobalResources context. The rest of the framework uses configuration (such as db connection info) can be declared in the application's context. Can something declared as a resource in the global context access a class created by a resource declaration in an application context? I did not think that it was possible, but that is how it seems to be - I verified it using a debugger.

2. As I mentioned above, the resource creates a thread in the background. When is the resource loaded - i.e. when is the factory method of the resource called? Based on my observations (using debuggers, etc), if the resource is declared in the global context, it is loaded when tomcat starts. If it is declared in the application context, the factory method is not called unless
a) It is called when a lookup is performed in the code, mentioned here - http://tomcat.apache.org/tomcat-6.0-doc/jndi-resourceshowto.html#Adding_Custom_Resource_Factories
Something like:


b) It is of type javax.sql.DataSource. This may sound strange, but here's the relevant code listing from the addResource method of org.apache.catalina.core.NamingContextListener class


As mentioned before, the webconsole needs to get the getinstance() method of its factory called. This can be done by putting it in the global context, but how does one do it by putting it in the META-INF/context.xml? Declaring the resource's type as javax.sql.DataSource may do the trick, but sounds like a real hack. Any suggestions?
6 years ago