1 Reply Latest reply on Jul 16, 2008 9:48 AM by jahhaj

    web service life cycle

    jahhaj

      I have a web service written using JAX-WS. It's deployed as a war file (does that matter? I could change if it does). The @WebService annotated class has some data fields which need one-time initialization.

      My first attempt to do this was in the constructor but I soon realised that the constructor is invoked every time a service method is invoked (twice actually). So I started reading and the @PostConstruct annotation seems to do what I want. However my method annotated with @PostConstruct is never called (it's a public void method with no parameters).

      What's the right method to do this? And why does @PostConstruct not seem to work?

      Thanks

        • 1. Re: web service life cycle
          jahhaj

          Fixed the problem, I added the @Stateless annotation to my service class, and deployed as a jar. Now my @PostConstruct method is called (and incidentally the ctor is only called once), which is exactly what I want.

          I'd appreciate some explanation of why this works however, and what the change I've made actually means. Programming EJB seems a bit like magic, if you know the right incantation then everything works smoothly, if you don't you're stuck.