Monday, August 16, 2010

xdoclet and AbstractStatelessSessionBean

I am working on a very old project to fix some bugs. It is using ejb 2.1 generated by xdoclet and spring 2.0.2.

To initial spring context from ejb, here is the code and the configuration

public abstract class CustomerServiceBean extends AbstractStatelessSessionBean implements SessionBean {
protected void onEjbCreate() throws CreateException {
customerService = (CustomerService) getBeanFactory().getBean("customerService");


<session > 

The env-entry point to the spring configuration file to load the spring context.

Here is the xdoclet tags to generate the configuration above

* …
* @ejb.env-entry name="ejb/BeanFactoryPath"
*  type="java.lang.String"
*  value="/smis-services-ejb-spring.xml"

Then we run the build script, deploy it and run the test. But “NullPointException” and the onEjbCreate() method is never executed. Why.. After look into the code generated by xdoclet, it generates an empty ejbCreate() which makes the onEjbCreate() method never be executed.

To avoid xdoclet doing that, explicitly create ejbCreate() method and it fixes this issue.

     * Don't remove this method, otherwise xdoclet generates a empty ejbCreate method
     * which makes onEjbCreate never executed
     * @ejb.create-method
    public void ejbCreate() throws CreateException {

No comments:

Post a Comment