I have an ordinary POJO class, from which I want to use the Seam logger.
I'm having a bit of trouble, however, using this POJO class, both from a Stateless
bean, and from a TestNG test class.
First, the Bean:
...
| @Stateless
| @Name("echo")
| public class EchoBean implements Echo {
| @Logger private Log log;
|
| @In
| FacesMessages facesMessages;
|
| @In
| Pojo pojo;
|
| public String echo() {
| log.info("echo.echo() action called");
|
| pojo.doEcho("Echo Me!");
|
| facesMessages.add("echo");
| return "success";
| }
| }
Then the POJO:
...
| @Name("pojo")
| public class Pojo {
| @Logger Log log;
|
| public String doEcho(String text) {
| log.info("Echoing: "+text);
| return text;
| }
| }
and for completeness, the TestNG testcase:
...
|
| public class PojoTests extends SeamTest {
| @In Pojo pojo;
|
| @Test
| public void testDoEcho() throws Exception {
| assert pojo.doEcho("hello world!").equals("hello world!");
| }
| }
At the moment, we're seeing this:
javax.ejb.EJBTransactionRolledbackException: org.jboss.seam.RequiredException: In
attribute requires value for component: echo.pojo
| at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:93)
| at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:130)
| at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:201)
| ...
I get basically the same problem from running inside a full JBoss AS install, as well as
the TestNG/Eclipse/embedded-ejb environment.
When we remove the '@In' parts from the calling class (either the testcase or the
bean) we get a NullPointerException in the POJO here:
log.info("Echoing: "+text);
which we take to mean that the logger isn't being injected for the POJO.
Is this even the correct approach? Basically the end-goal is to be able to use the logger
in POJOs as well as inside of beans, and to be able to use TestNG to unit test them.
Any help would be greatly appreciated :-)
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3990339#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...