-
1. Re: Logger (@Logger) is always null (NPE)
cjalmeida May 25, 2010 1:58 AM (in response to lrpieri)Try making
log
variable visibility default, protected or public. -
2. Re: Logger (@Logger) is always null (NPE)
lrpieri May 25, 2010 3:01 PM (in response to lrpieri)Hi Cloves,
The problem persist.
I think there are any generic injection problem in my tests or in the projects generated by jBoss Tools.Do you use jBoss Tools to generate your projects?
Thx.
Pieri
-
3. Re: Logger (@Logger) is always null (NPE)
lrpieri May 25, 2010 5:50 PM (in response to lrpieri)Hi All,
I've tried more two ways that work but they aren't what I'm looking for.
1st
on the view home.xhtml
... <h:form > <h:commandButton value="Login" action="#{pessoaDAO.list()}"/> </h:form> ...
PessoaDAO.java
@Name("pessoaDAO") public class PessoaDAOImpl{ @Logger Log log; public List<Pessoa> list(){ log.info("Entrou em list()"); return new ArrayList<Pessoa>(); } }
The 1st works fine.
2nd
on the view home.xhtml
... <h:form > <h:commandButton value="Login" action="#{pessoaHome.getList()}\"/> </h:form> ...
PessoaHome.java
@Name("pessoaHome") public class PessoaHome extends EntityHome<Pessoa> { ... @Logger private Log log; @In (create=true) private PessoaDAOImpl pessoaDAO; public List<Pessoa> getList(){ System.out.println("PessoaDAO: " + pessoaDAO); return pessoaDAO.list(); } }
The 2nd works fine
But...
If I change PessoaHome for:@Name("pessoaHome") public class PessoaHome extends EntityHome<Pessoa> { ... @Logger private Log public List<Pessoa> getList(){ PessoaDaoImp pessoaDAO = new PessoaDAOImpl(); System.out.println("PessoaDAO: " + pessoaDAO); return pessoaDAO.list(); } }
I'll get a NPE on log.info("Entrou em list()");
@Name("pessoaDAO") public class PessoaDAOImpl{ @Logger Log log; public List<Pessoa> list(){ log.info("Entrou em list()"); return new ArrayList<Pessoa>(); } }
What is wrong here?
Isn't enough for the PessoaDAOImpl have @Name to @Logger works?
Does it have to be used in a injection to work?
Or have to be used as a seam component?Thx for all.
-
4. Re: Logger (@Logger) is always null (NPE)
pmuir May 26, 2010 12:50 PM (in response to lrpieri)Please post in the Seam Users forum, this forum is for Weld only.
-
5. Re: Logger (@Logger) is always null (NPE)
hbender May 27, 2010 4:17 PM (in response to lrpieri)If you create the class directly with new operator, all the magic behind the annotations is gone. You have to let the seam framework do the job, like:
Component.getInstance( 'pessoaDAO' );
Heri
-
6. Re: Logger (@Logger) is always null (NPE)
cjalmeida Jun 1, 2010 7:47 PM (in response to lrpieri)As more people start using Weld, since the J2EE spec gives big publicity, this question will arise more often.
Maybe it should be the first line of the documentation, in big bold letters:
DON'T PANIC! And don't use the 'new' keyword. -
7. Re: Logger (@Logger) is always null (NPE)
piotguz Jul 19, 2010 5:30 AM (in response to lrpieri)Hi,
I had the same issue (null pointer exception at log) when I switched my SLSB to POJO.
What solved the problem was simply this:
org.jboss.logging.Logger log = new org.jboss.logging.Logger.getLogger(YourClass.class);
Ofcourse my object is still a seam managed object (with @Name annotation)
-
8. Re: Logger (@Logger) is always null (NPE)
isonisak Jan 1, 2011 11:55 AM (in response to lrpieri)I have this same error with Seam 2.2.1.CR2, JBoss 6 Final.
Application is generated by seam-gen and works fine.
When loggging is added comes always NPE no matter how logging is instantiated.
import org.jboss.seam.annotations.Logger;
@Logger public Log log;
log.debug(test seam logging
); -- NPE@Logger private Log log;
log.debug(test seam logging
); -- NPE@Logger Log log;
log.debug(test seam logging
); -- NPEIn JBoss AS 6 commmon lib is log4.jar and server start advertises this lib.
I copied this jar to ../default/lib.Result is the same. Maybe jar must be in applications libraries in this AS version ?
-
9. Re: Logger (@Logger) is always null (NPE)
isonisak Jan 5, 2011 1:27 AM (in response to lrpieri)Hai
This problem is not Seam version or platfrom spesific.
Probably the cause is that appropriate class where query is started
is not injected by Seam.
This is bad architecture for new Seam users and I suggest that
seam-gen is changed so, that server methods are called from UI so, that
@Logger works.This requires that methods are instantiated from UI with #{bean.method}
notation that causes, that Seam catches the call and injects Logger etc.Am I right ?
-
10. Re: Logger (@Logger) is always null (NPE)
jorgwel May 2, 2011 5:55 PM (in response to lrpieri)This assumption really helped me. I have the same
NullPointerException
with my loggers when I wasn't invoking methods from the UI. So Instead of keep using @In, I changed every injection point to something like this:(ResizeImageManager)Component.getInstance("resizeImageManager");
'Using the injection progamatically' , now all the
magic
in seam is working.Thanks for this post.
-
11. Re: Logger (@Logger) is always null (NPE)
marx3 May 4, 2011 9:49 AM (in response to lrpieri)Using injected logger is bad idea. For example such logger doesn't work in static method or in costructor.