You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Caterpillar <ca...@gmail.com> on 2014/01/12 12:00:42 UTC

Bean not instantiated

Hi, I am having a trouble with a bean that I cannot manage to
instantiate. It is so strange that even on Stackoverflow I don't get any
usefull help.
I also tried to test other beans in the same project and they work
correctly...
You can find an extensive explanation here:
http://stackoverflow.com/questions/21017979/bean-not-instantiated

Thank you for your time

Re: Bean not instantiated

Posted by Caterpillar <ca...@gmail.com>.
Hi, I solved the problem of the topic with your suggestions. Now if I put
some console prints in the LoginController's methods, I can read them in
console, so basically the bean is working. Now my next step will be to find
out why the web page does not say anything about username and password,
even if the bean is correctly getting the infos from the webpage (as I can
see from console prints).
Thank you very much!

Re: Bean not instantiated

Posted by Romain Manni-Bucau <rm...@gmail.com>.
well both are true so as usual the conclusion is "depend on your
case". BTW static is almost always fine in practise for standard apps.
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau



2014/1/13 Howard W. Smith, Jr. <sm...@gmail.com>:
> more to share, below.
>
> On Mon, Jan 13, 2014 at 7:06 AM, Howard W. Smith, Jr. <
> smithh032772@gmail.com> wrote:
>
>> Okay, never mind. I took the liberty to search google for:
>>
>> static Logger logger = LoggerFactory
>>
>> and found this[1], which makes it abundantly clear why I should define the
>> logger as 'static'. As always, thanks Romain!
>>
>>
>> [1]
>> http://stackoverflow.com/questions/6653520/why-do-we-declare-loggers-static-final
>>
>
> While I reading stackoverflow question/answers (URL above), someone
> referenced the URL below,
>
> http://www.slf4j.org/faq.html#declared_static
>
> which references the following:
>
> http://wiki.apache.org/commons/Logging/StaticLog
>
> I also recognized that I +1 that stackoverflow question and Tomasz answer
> some time in the past, so i think I 'avoided' static, because of all the
> URLs I mentioned above.

Re: Bean not instantiated

Posted by "Howard W. Smith, Jr." <sm...@gmail.com>.
more to share, below.

On Mon, Jan 13, 2014 at 7:06 AM, Howard W. Smith, Jr. <
smithh032772@gmail.com> wrote:

> Okay, never mind. I took the liberty to search google for:
>
> static Logger logger = LoggerFactory
>
> and found this[1], which makes it abundantly clear why I should define the
> logger as 'static'. As always, thanks Romain!
>
>
> [1]
> http://stackoverflow.com/questions/6653520/why-do-we-declare-loggers-static-final
>

While I reading stackoverflow question/answers (URL above), someone
referenced the URL below,

http://www.slf4j.org/faq.html#declared_static

which references the following:

http://wiki.apache.org/commons/Logging/StaticLog

I also recognized that I +1 that stackoverflow question and Tomasz answer
some time in the past, so i think I 'avoided' static, because of all the
URLs I mentioned above.

Re: Bean not instantiated

Posted by "Howard W. Smith, Jr." <sm...@gmail.com>.
Surprises? Interesting! Please do tell/clarify/elaborate or provide some
examples of surprises.

So far, I have not seen any surprises at all.

Okay, never mind. I took the liberty to search google for:

static Logger logger = LoggerFactory

and found this[1], which makes it abundantly clear why I should define the
logger as 'static'. As always, thanks Romain!


[1]
http://stackoverflow.com/questions/6653520/why-do-we-declare-loggers-static-final



On Mon, Jan 13, 2014 at 1:58 AM, Romain Manni-Bucau
<rm...@gmail.com>wrote:

> @Howard: make it static otherwise you can get surprises :p
> Romain Manni-Bucau
> Twitter: @rmannibucau
> Blog: http://rmannibucau.wordpress.com/
> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> Github: https://github.com/rmannibucau
>
>
>
> 2014/1/13 Howard W. Smith, Jr. <sm...@gmail.com>:
> > On Sun, Jan 12, 2014 at 11:44 AM, Romain Manni-Bucau
> > <rm...@gmail.com>wrote:
> >
> >> Side note: producing a logger is a wrong idea (see codi list to learn
> >> why) so maybe just get rid of it
> >>
> >
> > +1
> >
> > My SLF4J example below.
> >
> >
> > import org.slf4j.Logger;
> > import org.slf4j.LoggerFactory;
> >
> > @Named("myController")
> > @SessionScoped
> > public class MyController implements Serializable {
> >
> >     private final Logger logger = LoggerFactory.getLogger(getClass());
> >
> >         // of course, this is inside some method
> >         try {
> >            ...
> >         } catch (Exception e) {
> >             logger.error("caught exception:", e);
> >         }
>

Re: Bean not instantiated

Posted by Romain Manni-Bucau <rm...@gmail.com>.
@Howard: make it static otherwise you can get surprises :p
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau



2014/1/13 Howard W. Smith, Jr. <sm...@gmail.com>:
> On Sun, Jan 12, 2014 at 11:44 AM, Romain Manni-Bucau
> <rm...@gmail.com>wrote:
>
>> Side note: producing a logger is a wrong idea (see codi list to learn
>> why) so maybe just get rid of it
>>
>
> +1
>
> My SLF4J example below.
>
>
> import org.slf4j.Logger;
> import org.slf4j.LoggerFactory;
>
> @Named("myController")
> @SessionScoped
> public class MyController implements Serializable {
>
>     private final Logger logger = LoggerFactory.getLogger(getClass());
>
>         // of course, this is inside some method
>         try {
>            ...
>         } catch (Exception e) {
>             logger.error("caught exception:", e);
>         }

Re: Bean not instantiated

Posted by "Howard W. Smith, Jr." <sm...@gmail.com>.
On Sun, Jan 12, 2014 at 11:44 AM, Romain Manni-Bucau
<rm...@gmail.com>wrote:

> Side note: producing a logger is a wrong idea (see codi list to learn
> why) so maybe just get rid of it
>

+1

My SLF4J example below.


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Named("myController")
@SessionScoped
public class MyController implements Serializable {

    private final Logger logger = LoggerFactory.getLogger(getClass());

        // of course, this is inside some method
        try {
           ...
        } catch (Exception e) {
            logger.error("caught exception:", e);
        }

Re: Bean not instantiated

Posted by Romain Manni-Bucau <rm...@gmail.com>.
+ Logger is generally not Serializable and CDI 1.0 makes it not
injectable in passivation capable scope (I resume it but that's the
idea)
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau



2014/1/12 John D. Ament <jo...@gmail.com>:
> CODI is a set of CDI components, however it's more or less migrated
> over to DeltaSpike.
>
> I responded to your question on stack overflow.  I generally agree
> with Romain's comment, injecting a logger makes very little sense,
> since you're just wrapping it (the LOC to make a logger producer far
> outweigh using a static final logger; using an instance level logger
> has certain distinctive behavior).
>
> On Sun, Jan 12, 2014 at 11:59 AM, Caterpillar <ca...@gmail.com> wrote:
>> Il 12/01/2014 17:44, Romain Manni-Bucau ha scritto:
>>> Side note: producing a logger is a wrong idea (see codi list to learn
>>> why) so maybe just get rid of it
>>> Romain Manni-Bucau
>>> Twitter: @rmannibucau
>>> Blog: http://rmannibucau.wordpress.com/
>>> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>>> Github: https://github.com/rmannibucau
>> What is codi list?

Re: Bean not instantiated

Posted by "John D. Ament" <jo...@gmail.com>.
CODI is a set of CDI components, however it's more or less migrated
over to DeltaSpike.

I responded to your question on stack overflow.  I generally agree
with Romain's comment, injecting a logger makes very little sense,
since you're just wrapping it (the LOC to make a logger producer far
outweigh using a static final logger; using an instance level logger
has certain distinctive behavior).

On Sun, Jan 12, 2014 at 11:59 AM, Caterpillar <ca...@gmail.com> wrote:
> Il 12/01/2014 17:44, Romain Manni-Bucau ha scritto:
>> Side note: producing a logger is a wrong idea (see codi list to learn
>> why) so maybe just get rid of it
>> Romain Manni-Bucau
>> Twitter: @rmannibucau
>> Blog: http://rmannibucau.wordpress.com/
>> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>> Github: https://github.com/rmannibucau
> What is codi list?

Re: Bean not instantiated

Posted by Caterpillar <ca...@gmail.com>.
Il 12/01/2014 17:44, Romain Manni-Bucau ha scritto:
> Side note: producing a logger is a wrong idea (see codi list to learn
> why) so maybe just get rid of it
> Romain Manni-Bucau
> Twitter: @rmannibucau
> Blog: http://rmannibucau.wordpress.com/
> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> Github: https://github.com/rmannibucau
What is codi list?

Re: Bean not instantiated

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Side note: producing a logger is a wrong idea (see codi list to learn
why) so maybe just get rid of it
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau



2014/1/12 Jean-Louis MONTEIRO <je...@gmail.com>:
> There are plenty of producer example over the internet. Even in the spec
> itself producing a logger is shown. There are usually also a couple of
> samples with producing entity managers.
>
> Yes let us know please.
> Le 12 janv. 2014 17:16, "Caterpillar" <ca...@gmail.com> a écrit :
>
>> Il 12/01/2014 16:32, Jean-Louis MONTEIRO ha scritto:
>> > Ok so the good news is that your bean is found and being managed by cdi.
>> >
>> > But your are trying to inject a logger which isn't managed by cdi.
>> >
>> > Try adding a producer, common way to do.
>> Ok. Not having experience with producer, I opened a S.O. question about
>> how to use it in that bean.
>>
>> http://stackoverflow.com/questions/21076836/logger-convert-from-inject-to-producer
>> As soon I receive an answer I will do a test and I will let you know.
>>
>> Thank you very much.
>>

Re: Bean not instantiated

Posted by Jean-Louis MONTEIRO <je...@gmail.com>.
There are plenty of producer example over the internet. Even in the spec
itself producing a logger is shown. There are usually also a couple of
samples with producing entity managers.

Yes let us know please.
Le 12 janv. 2014 17:16, "Caterpillar" <ca...@gmail.com> a écrit :

> Il 12/01/2014 16:32, Jean-Louis MONTEIRO ha scritto:
> > Ok so the good news is that your bean is found and being managed by cdi.
> >
> > But your are trying to inject a logger which isn't managed by cdi.
> >
> > Try adding a producer, common way to do.
> Ok. Not having experience with producer, I opened a S.O. question about
> how to use it in that bean.
>
> http://stackoverflow.com/questions/21076836/logger-convert-from-inject-to-producer
> As soon I receive an answer I will do a test and I will let you know.
>
> Thank you very much.
>

Re: Bean not instantiated

Posted by Caterpillar <ca...@gmail.com>.
Il 12/01/2014 16:32, Jean-Louis MONTEIRO ha scritto:
> Ok so the good news is that your bean is found and being managed by cdi.
>
> But your are trying to inject a logger which isn't managed by cdi.
>
> Try adding a producer, common way to do.
Ok. Not having experience with producer, I opened a S.O. question about
how to use it in that bean.
http://stackoverflow.com/questions/21076836/logger-convert-from-inject-to-producer
As soon I receive an answer I will do a test and I will let you know.

Thank you very much.

Re: Bean not instantiated

Posted by Jean-Louis MONTEIRO <je...@gmail.com>.
Ok so the good news is that your bean is found and being managed by cdi.

But your are trying to inject a logger which isn't managed by cdi.

Try adding a producer, common way to do.
Le 12 janv. 2014 16:24, "Caterpillar" <ca...@gmail.com> a écrit :

> Il 12/01/2014 16:16, Jean-Louis MONTEIRO ha scritto:
> > I'm not at home right now. Give it a try with an empty web-inf/beans.xml
> > It's just a marker to enable cdi.
> >
> > If u have am error starting tomee, copy/paste it.
> >
> > Jean Louis
> TomEE console: http://pastebin.com/x9Xh92Ab
> Thank you
>

Re: Bean not instantiated

Posted by Caterpillar <ca...@gmail.com>.
Il 12/01/2014 16:16, Jean-Louis MONTEIRO ha scritto:
> I'm not at home right now. Give it a try with an empty web-inf/beans.xml
> It's just a marker to enable cdi.
>
> If u have am error starting tomee, copy/paste it.
>
> Jean Louis
TomEE console: http://pastebin.com/x9Xh92Ab
Thank you

Re: Bean not instantiated

Posted by Jean-Louis MONTEIRO <je...@gmail.com>.
I'm not at home right now. Give it a try with an empty web-inf/beans.xml
It's just a marker to enable cdi.

If u have am error starting tomee, copy/paste it.

Jean Louis
Le 12 janv. 2014 16:11, "Caterpillar" <ca...@gmail.com> a écrit :

> Il 12/01/2014 12:47, Jean-Louis MONTEIRO ha scritto:
> > Hi,
> >
> > Any way you could share the project on github or even a zip file?
> > I guess you checked there is a beans.xml?
> >
> > Jean Louis
> > Le 12 janv. 2014 12:01, "Caterpillar" <ca...@gmail.com> a écrit
> :
> Is it okay to share it on Wuala?
>
> https://www.wuala.com/Caterpillar/Documenti/canc/LAI_pezzi_Login/?key=vtkJrAL6ZykH
> I missed to add beans.xml, and I tried to use the one from SimTay's
> example, but it causes TomEE boot failure.
> I added also some other infos at the Romain answer on StackOverflow.
>

Re: Bean not instantiated

Posted by Caterpillar <ca...@gmail.com>.
Il 12/01/2014 12:47, Jean-Louis MONTEIRO ha scritto:
> Hi,
>
> Any way you could share the project on github or even a zip file?
> I guess you checked there is a beans.xml?
>
> Jean Louis
> Le 12 janv. 2014 12:01, "Caterpillar" <ca...@gmail.com> a écrit :
Is it okay to share it on Wuala?
https://www.wuala.com/Caterpillar/Documenti/canc/LAI_pezzi_Login/?key=vtkJrAL6ZykH
I missed to add beans.xml, and I tried to use the one from SimTay's
example, but it causes TomEE boot failure.
I added also some other infos at the Romain answer on StackOverflow.

Re: Bean not instantiated

Posted by Jean-Louis MONTEIRO <je...@gmail.com>.
Hi,

Any way you could share the project on github or even a zip file?
I guess you checked there is a beans.xml?

Jean Louis
Le 12 janv. 2014 12:01, "Caterpillar" <ca...@gmail.com> a écrit :

> Hi, I am having a trouble with a bean that I cannot manage to
> instantiate. It is so strange that even on Stackoverflow I don't get any
> usefull help.
> I also tried to test other beans in the same project and they work
> correctly...
> You can find an extensive explanation here:
> http://stackoverflow.com/questions/21017979/bean-not-instantiated
>
> Thank you for your time
>

Re: Bean not instantiated

Posted by Romain Manni-Bucau <rm...@gmail.com>.
anwsered on stackoverflow but: did you put a beans.xml in WEB-INF?
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau



2014/1/12 Caterpillar <ca...@gmail.com>:
> Hi, I am having a trouble with a bean that I cannot manage to
> instantiate. It is so strange that even on Stackoverflow I don't get any
> usefull help.
> I also tried to test other beans in the same project and they work
> correctly...
> You can find an extensive explanation here:
> http://stackoverflow.com/questions/21017979/bean-not-instantiated
>
> Thank you for your time