Hi Scott,
You rock!! Its works!!! I can see my service startup at the host level
prior to the web applications loading. Thanks a lot.
Keith
On 03/17/2011 03:29 PM, Scott Ferguson wrote:
On 03/17/2011 03:04 PM, Keith Fetterman wrote:
Hi Scott,
How do you configure services using CanDI at the host level and have
them loaded before the Web applications are loaded? Our Web site is
currently running on resin 3.0.28. Our Web site runs several Web
applications, and we have custom resources that are shared across all
Web applications running on a host. All of the classes are loaded
using a host level classloader. We are using the <resource> tags in
the resin.conf file that are located under the <host> tag to specify
the shared resources.
All of the CanDI examples on the Caucho Web site are specific to a
Web application and use the resin-web.xml file for XML
configuration. Is it possible to load and initialize services at the
host level using CanDI?
It should just work. CanDI works with Resin's existing classloader
structure. So a configuration in the <host> will create a CanDI bean
shared across all the webapps and a configuration in the <cluster>
will create a CanDI bean shared across the entire server.
The new CanDI configuration should directly replace the <resource>
configuration. (The <resource> should still work for backwards compat,
but we'd encourage upgrading.)
The examples all use resin-web.xml for simplicity, so we don't need to
explain Resin's nested classloader structure.
The default configuration of resin 3.0.28 creates a WEB-INF directory
in the webapps directory for a host. I noticed that the default
configuration of 4.0.15 didn't create this WEB-INF. One thought I
have is to create a WEB-INF directory in the webapps directory under
the host root directory and then create a resin-web.xml and/or
beans.xml files underneath.
You can do that. Try something like:
...
<host id="...">
<class-loader>
<compiling-loader path="WEB-INF/classes"/>
<library-loader path="WEB-INF/lib"/>
</class-loader>
<resin:import path="WEB-INF/resin-host.xml" optional="true"/>
(Or use a <host-default> to make it work for all hosts.)
If you look at the conf/app-default.xml, you can see that the web-app
classloaders and special files are configured by the
resin.xml/app-default.xml. (I just did that to cut-and-past the sample
XML above) In Resin 4.0, we try to stay away from internal defaults,
and expose everything in the config files where possible.
The host level web-resin.xml file could be defined like the example
on the Caucho Web site:
| <web-app xmlns="http://caucho.com/ns/resin"
xmlns:ee="urn:java:ee">
<mypkg:MyBean xmlns:mypkg="urn:java:com.mycom.mypkg">
<ee:Startup/>
</mypkg:MyBean>
</web-app>
|
Exactly. That's what the resin-host.xml above would do.
The only difference is that you'd use <host
xmlns="http://caucho.com/ns/resin"> because the <resin:import> is from
the <host> context.
Or the above could be added to the resin.xml file like we do with the
<resource> tag today in the resin.conf file.
Well this work?
Yep.
If so, is this a recommended approach?
Sure. The only reason we've avoided discussing it much is to avoid
making the configuration look too complicated. For services/beans
shared across an entire host, it's the right solution.
-- Scott
Or is there a better way?
Thanks,
Keith
On 03/17/2011 10:47 AM, Scott Ferguson wrote:
On 03/17/2011 10:36 AM, Keith Fetterman wrote:
I need some help understanding how CanDI works with the Startup
pattern mentioned in the following tutorial on Caucho's Web site.
I have added the two annotations @Startup and @PostConstruct to the
class that I want to load at server initialization time, but when I
start Resin, the class is not initialized. My understanding from
reading the tutorial is that this is all I should have to do to
have the class loaded and initialized. But, it doesn't seem to
work. I don't think Resin is scanning the classpath or finding the
class in the classpath. Is there more to it than this?
Do you have a META-INF/beans.xml in the .jar (or classes directory)
containing the bean?
For performance reasons, CDI scanning only occurs in jars which have
the beans.xml file. (Or if you add it to the resin-web.xml of course.)
-- Scott
Here is my Java class:
package example;
import javax.annotation.PostConstruct;
import javax.ejb.Startup;
import javax.inject.Inject;
@Startup
public class MyStartupBean {
{
System.out.println("MyStartupBean instance loaded");
}
@PostConstruct
public void init()
{
System.out.println("MyStartupBean.init() ran");
}
}
This Java class is located in the webapp's WEB-INF/classes folder
(in the example package).
I see Resin compiling it, but I don't see the print messages in the
stdout log.
Do I need to add something to the resin.xml or the webapp's
web-resin.xml file to get it to load?
I did figure out a way to explicitly tell Resin to load the class.
I created a resin-web.xml file in my web application with the
following statements:
<web-app xmlns="http://caucho.com/ns/resin" xmlns:ee="urn:java:ee"
xmlns:example="urn:java:example">
<example:MyStartupBean>
<ee:Startup/>
</example:MyStartupBean>
</web-app>
Now when resin starts, I see the class loading and the init()
method is run.
Should this be required?
Thanks for any help.
Keith
--
-----------------------------------------------------------------
Keith Fetterman Direct: 206-319-9434
Mariner Supply, Inc. 206-780-5670
http://www.go2marine.com [email protected]
http://www.boatersline.com
_______________________________________________
resin-interest mailing list
[email protected]
http://maillist.caucho.com/mailman/listinfo/resin-interest
--
-----------------------------------------------------------------
Keith Fetterman Direct: 206-319-9434
Mariner Supply, Inc. 206-780-5670
http://www.go2marine.com [email protected]
http://www.boatersline.com
_______________________________________________
resin-interest mailing list
[email protected]
http://maillist.caucho.com/mailman/listinfo/resin-interest
--
-----------------------------------------------------------------
Keith Fetterman Direct: 206-319-9434
Mariner Supply, Inc. 206-780-5670
http://www.go2marine.com [email protected]
http://www.boatersline.com
_______________________________________________
resin-interest mailing list
[email protected]
http://maillist.caucho.com/mailman/listinfo/resin-interest