I created a plain servlet within a seam-gen (2.1.2) application, now I would like to use injection. Thus I annotated it with @Name and it’s recognized as component:
INFO [Component] Component: ConfigReport,
scope: EVENT, type: JAVA_BEAN, class: com.mycompany.servlet.ConfigReport
Unfortunatly the injection of the logger doesn’t work NullPointerException in init()
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.log.Log;
@Name("ConfigReport")
public class ConfigReport extends HttpServlet {
@Logger
private Log log;
public void init(ServletConfig config) throws ServletException {
log.info( "BOOM" );
}
}
Is my approach abusive?
What would be the alternatives (the client sending requests to the servlet is curl, not a browser)?
Stacker, if you want Seam @In-ject any enabled component, It must intercept your request. For instance, @In-jection works when using EJB because Seam uses an EJB interceptor. It explains why you should declare Seam EJB interceptor when using EJB.
Java Server Faces, in other hand, Seam makes use of Expression Language resolver, to give you access To any Seam component, which is installed by default when Seam core jar is placed on the classpath.
The key to enable Seam integration with any web Technology is ContextFilter – Be aware you must enable Seam Filter to use ContextFilter – which is described according to Seam in Action book as follows
…
To enable ContextFilter you declare it in components.xml
Because no spare Time, i do not know how to use this kind of funcionality. Take a look at ContextFilter source code. It can give you a good insight.