Hi,

you speak about rest services right?

you are right but if you use an ejb instead it should be fine.

I'll have a look soon on this topic

- Romain


2012/5/30 tom <[email protected]>

> Hi,
>
> I am using apache-tomee-1.0.0-plus(clean, no additional jars) and while
> playing around with some dependency injection I stumbled upon a strange
> behavior:
>
> The method annotated with @PostConstruct gets called before the variables
> are injected. According to the @PostConstruct JavaDoc it should be the
> other
> way around.
>
> So the Dependency Injection and the PostConstruct work, but I can't think
> of
> a way to change the order.
>
> At this moment I don't have a way to upload my war file, so I´ll just list
> what my project contains so far:
>
> It is a maven-archetype-webapp project
>
> The web.xml looks like this:
>
> <web-app xmlns="http://java.sun.com/xml/ns/javaee";
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
> xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
> http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd";
>        metadata-complete="false" version="2.5">
>
>        <display-name>OpenEJB REST Example</display-name>
>
>        <filter>
>                <filter-name>TestFilter</filter-name>
>                <filter-class>a.b.c.TestFilter</filter-class>
>                <init-param>
>                        <param-name>testfilter</param-name>
>                        <param-value>testfilter</param-value>
>                </init-param>
>        </filter>
>
>        <filter-mapping>
>                <filter-name>TestFilter</filter-name>
>                <url-pattern>/*</url-pattern>
>        </filter-mapping>
>
> </web-app>
>
> Whereas the filter actually does nothing.
>
> The class containing @PostConstruct:
>
> package a.b.c;
>
> import javax.annotation.PostConstruct;
> import javax.inject.Inject;
> import javax.ws.rs.GET;
> import javax.ws.rs.Path;
>
> @Path("hello")
> public class Hello {
>
>    @Inject
>    private Greeting mGreeting;
>
>    @PostConstruct
>    public void init(){
>        String tmp = "test";
>    }
>
>    @GET
>    public String hello(){
>        if(mGreeting == null){
>            return "Well, it still doesn't work...";
>        }else{
>            return mGreeting.greet();
>        }
>    }
> }
>
> The String tmp = "test" is just there so I can set a breakpoint.
>
>
> And the injected Greeting class:
>
> package a.b.c;
>
> public class Greeting {
>
>    public String greet(){
>        return "Greetings";
>    }
> }
>
> So maybe I am doing something completely wrong here. ^^
>
> Thanks in advance :)
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/PostConstruct-method-called-before-injection-occurred-tp4655229.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Reply via email to