Tomcat7AnnotationLifecycleProvider calls Tomcat 7 Instancemanager for creation of MB instance and injection of annotations. Because Tomcat7 InstanceManager does not understand to inject @ManagedProperty this field is null. You can write your own instance manager.

Gurkan Erdogdu
added a comment - 18/Feb/11 18:02 Tomcat7AnnotationLifecycleProvider calls Tomcat 7 Instancemanager for creation of MB instance and injection of annotations. Because Tomcat7 InstanceManager does not understand to inject @ManagedProperty this field is null. You can write your own instance manager.

Now, the old processAnnotations() and postConstruct() code was merged in newInstance(Object o).

The solution is just call this code from LifecycleProvider2.postConstruct, so managed properties are injected before postConstruct. In theory, the shouldn't be any problem, because we don't have a case were managed properties needs to be injected before processAnnotations code occur.

Leonardo Uribe
added a comment - 18/Feb/11 19:38 I checke it and the problem is caused by the place used to call InstanceManager.newInstance. In tomcat 6 there is an interface called AnnotationProcessor:
public interface AnnotationProcessor
{
public void postConstruct(Object instance)
throws IllegalAccessException, InvocationTargetException;
public void preDestroy(Object instance)
throws IllegalAccessException, InvocationTargetException;
public void processAnnotations(Object instance)
throws IllegalAccessException, InvocationTargetException, NamingException;
}
In tomcat 7.0 it was replaced by this interface:
public interface InstanceManager
{
public Object newInstance(String className)
throws IllegalAccessException, InvocationTargetException, NamingException,
InstantiationException, ClassNotFoundException;
public Object newInstance(String fqcn, ClassLoader classLoader)
throws IllegalAccessException, InvocationTargetException, NamingException,
InstantiationException, ClassNotFoundException;
public void newInstance(Object o)
throws IllegalAccessException, InvocationTargetException, NamingException;
public void destroyInstance(Object o)
throws IllegalAccessException, InvocationTargetException;
}
Now, the old processAnnotations() and postConstruct() code was merged in newInstance(Object o).
The solution is just call this code from LifecycleProvider2.postConstruct, so managed properties are injected before postConstruct. In theory, the shouldn't be any problem, because we don't have a case were managed properties needs to be injected before processAnnotations code occur.

Jay Balunas
added a comment - 18/Feb/11 20:50 The weld team did write their own instance manager. I believe the details are linked from the jira I commented on above. There code is up on github if you wanted to look.