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?

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. 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>
|

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? If so, is this a recommended approach? 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                kfetter...@go2marine.com

http://www.boatersline.com


_______________________________________________
resin-interest mailing list
resin-interest@caucho.com
http://maillist.caucho.com/mailman/listinfo/resin-interest


--
-----------------------------------------------------------------
Keith Fetterman                        Direct: 206-319-9434
Mariner Supply, Inc.                   206-780-5670
http://www.go2marine.com               kfetter...@go2marine.com

http://www.boatersline.com


_______________________________________________
resin-interest mailing list
resin-interest@caucho.com
http://maillist.caucho.com/mailman/listinfo/resin-interest

Reply via email to