[JBoss Seam] - @Logger use in POJO (& TestNG)
by joff
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#3990339
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3990339
18 years
[JBoss Seam] - Re: @Out and default ScopeType
by dan.j.allen
I understand my problem. In this particular case, my entity being outjected is a Seam component but not marked with a scope. Therefore, it is taking on the default EVENT scope. If I don't specify the scope on the @Out annotation, my data is placed in the event context, and thus the data does not survive past the redirect. If I add @Scope(CONVERSATION) atop the User class, then it works as expected.
So the point is that it is required to add @Scope(CONVERSATION) either on the entity or on the scope attribute of the @Out annotation for the data to be included in the conversation context if the data IS a seam component. If the User class was not a Seam component, then it would default to the scope of the component outjecting the data. I managed to find myself right between the two scenarios, and hence out of luck.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3990338#3990338
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3990338
18 years