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

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

Reply via email to