Re: Autowired and PostConstruct with Struts + Spring
How is your JUnit test setup? If your service is injected in your JUnit test and not in Struts then it could be that contextConfiguration in web.xml is messed up. I usually annotate the action with @Component and just put an @Autowired over the setter. I am not sure what @PostConstruct does. e_sli...@yahoo.it wrote: > > Hi Norris and Dave! > > Thank you for your answers. > Yes, I have get/set methods for myService. > > If you means declaring: value="spring" /> in my struts.xml for my object factory, yes. I don't > have @Component for Spring injection, but I suppose Spring work well as > far as the myService bean is available in my context for other beans in my > app. > > I'm just wondering about @Autowired and @PostConstruct behaviour when > passing by Struts + Spring. > Probably @PostConstruct is executed just before the @Autowired? > Using pure Spring without Struts works well: running a JUnit test with my > @PostConstruct annotated method show myService is not null, but when this > is in a Struts action does not work... > > Has anybody see this behaviour? > > Thank you for your help! > > Emanuele > > Norris Shelton wrote: >> Did you set Spring to be your object factory in your struts.xml. If you >> used Spring annotations, did you annotate your bean to be injected with >> @Component and designate a base package for Spring to scan for beans? >> >> >> Norris Shelton >> Software Engineer >> Sun Certified Java 1.1 Programmer >> Shelton Consulting, LLC >> ICQ# 26487421 >> AIM NorrisEShelton >> YIM norrisshelton >> >> Is there a public myService setter? >> >> (I hardly even use annotations; maybe that's not necessary?) >> >> Dave >> >> >> >> >> From: "e_sli...@yahoo.it" >> To: user@struts.apache.org >> Sent: Monday, April 27, 2009 12:41:01 PM >> Subject: Autowired and PostConstruct with Struts + Spring >> >> Hello everybody! >> >> I'm trying to use my service into a Struts action but with no success. >> >> My struts action contains : >> >> @Autowired >> private MyService myService >> >> @PostConstruct >> public void init() { >> // use here myService >> } >> >> Unfortunately myService is always null and I cannot use myService in the >> init() method... >> >> The bean myService should correctly declared in my >> application-context.xml: >> >> >> ... >> >> >> and my struts.xml contains: >> >> >> Where I'm wrong? >> Many Thanks! >> >> Emanuele >> >> >> > > > > > -- View this message in context: http://www.nabble.com/Autowired-and-PostConstruct-with-Struts-%2B-Spring-tp23260298p23290503.html Sent from the Struts - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: Autowired and PostConstruct with Struts + Spring
Wow. I really shouldn't try to help people when I am on a diet. My brain does not work. Get rid of the @PostExecute and change that method to execute. You should be able to set a break-point within your execute method and see that myService has been initialized. My struts action contains : @Autowired private MyService myService public String execute() { // use here myService } Norris Shelton Software Engineer Sun Certified Java 1.1 Programmer Shelton Consulting, LLC ICQ# 26487421 AIM NorrisEShelton YIM norrisshelton From: Norris Shelton To: Struts Users Mailing List ; e_sli...@yahoo.it Sent: Monday, April 27, 2009 4:09:27 PM Subject: Re: Autowired and PostConstruct with Struts + Spring I have a question. Why are you using PostConstruct anyway? AFAIK, a new action is created for each request. This is not going to work like a servlet where it is created, you perform some initialization. I think the problem is caused by the mixing of APIs. My guess is that whatever you are trying to do in the @PostConstruct annotated method should be in your annotate. Norris Shelton Software Engineer Sun Certified Java 1.1 Programmer Shelton Consulting, LLC ICQ# 26487421 AIM NorrisEShelton YIM norrisshelton From: "e_sli...@yahoo.it" To: user@struts.apache.org Sent: Monday, April 27, 2009 3:29:38 PM Subject: Re: Autowired and PostConstruct with Struts + Spring Hi Norris and Dave! Thank you for your answers. Yes, I have get/set methods for myService. If you means declaring: in my struts.xml for my object factory, yes. I don't have @Component for Spring injection, but I suppose Spring work well as far as the myService bean is available in my context for other beans in my app. I'm just wondering about @Autowired and @PostConstruct behaviour when passing by Struts + Spring. Probably @PostConstruct is executed just before the @Autowired? Using pure Spring without Struts works well: running a JUnit test with my @PostConstruct annotated method show myService is not null, but when this is in a Struts action does not work... Has anybody see this behaviour? Thank you for your help! Emanuele Norris Shelton wrote: > Did you set Spring to be your object factory in your struts.xml. If you used > Spring annotations, did you annotate your bean to be injected with @Component > and designate a base package for Spring to scan for beans? > > > Norris Shelton > Software Engineer > Sun Certified Java 1.1 Programmer > Shelton Consulting, LLC > ICQ# 26487421 > AIM NorrisEShelton > YIM norrisshelton > > Is there a public myService setter? > > (I hardly even use annotations; maybe that's not necessary?) > > Dave > > > > > From: "e_sli...@yahoo.it" > To: user@struts.apache.org > Sent: Monday, April 27, 2009 12:41:01 PM > Subject: Autowired and PostConstruct with Struts + Spring > > Hello everybody! > > I'm trying to use my service into a Struts action but with no success. > > My struts action contains : > > @Autowired > private MyService myService > > @PostConstruct > public void init() { > // use here myService > } > > Unfortunately myService is always null and I cannot use myService in the > init() method... > > The bean myService should correctly declared in my application-context.xml: > > > ... > > > and my struts.xml contains: > > > Where I'm wrong? > Many Thanks! > > Emanuele > > >
Re: Autowired and PostConstruct with Struts + Spring
I have a question. Why are you using PostConstruct anyway? AFAIK, a new action is created for each request. This is not going to work like a servlet where it is created, you perform some initialization. I think the problem is caused by the mixing of APIs. My guess is that whatever you are trying to do in the @PostConstruct annotated method should be in your annotate. Norris Shelton Software Engineer Sun Certified Java 1.1 Programmer Shelton Consulting, LLC ICQ# 26487421 AIM NorrisEShelton YIM norrisshelton From: "e_sli...@yahoo.it" To: user@struts.apache.org Sent: Monday, April 27, 2009 3:29:38 PM Subject: Re: Autowired and PostConstruct with Struts + Spring Hi Norris and Dave! Thank you for your answers. Yes, I have get/set methods for myService. If you means declaring: in my struts.xml for my object factory, yes. I don't have @Component for Spring injection, but I suppose Spring work well as far as the myService bean is available in my context for other beans in my app. I'm just wondering about @Autowired and @PostConstruct behaviour when passing by Struts + Spring. Probably @PostConstruct is executed just before the @Autowired? Using pure Spring without Struts works well: running a JUnit test with my @PostConstruct annotated method show myService is not null, but when this is in a Struts action does not work... Has anybody see this behaviour? Thank you for your help! Emanuele Norris Shelton wrote: > Did you set Spring to be your object factory in your struts.xml. If you used > Spring annotations, did you annotate your bean to be injected with @Component > and designate a base package for Spring to scan for beans? > > > Norris Shelton > Software Engineer > Sun Certified Java 1.1 Programmer > Shelton Consulting, LLC > ICQ# 26487421 > AIM NorrisEShelton > YIM norrisshelton > > Is there a public myService setter? > > (I hardly even use annotations; maybe that's not necessary?) > > Dave > > > > > From: "e_sli...@yahoo.it" > To: user@struts.apache.org > Sent: Monday, April 27, 2009 12:41:01 PM > Subject: Autowired and PostConstruct with Struts + Spring > > Hello everybody! > > I'm trying to use my service into a Struts action but with no success. > > My struts action contains : > > @Autowired > private MyService myService > > @PostConstruct > public void init() { > // use here myService > } > > Unfortunately myService is always null and I cannot use myService in the > init() method... > > The bean myService should correctly declared in my application-context.xml: > > > ... > > > and my struts.xml contains: > > > Where I'm wrong? > Many Thanks! > > Emanuele > > >
Re: Autowired and PostConstruct with Struts + Spring
Check you only have one ocurrence of "myService" in your spring configuration specially if it's in more than one file. Maybe there is more than one instance and spring uses the "last wins" design principle. Si quieres ser más positivo, pierde un electrón Miguel Ruiz Velasco Sobrino On Mon, Apr 27, 2009 at 14:29, e_sli...@yahoo.it wrote: > Hi Norris and Dave! > > Thank you for your answers. > Yes, I have get/set methods for myService. > > If you means declaring: /> in my struts.xml for my object factory, yes. I don't have @Component for > Spring injection, but I suppose Spring work well as far as the myService bean > is available in my context for other beans in my app. > > I'm just wondering about @Autowired and @PostConstruct behaviour when passing > by Struts + Spring. > Probably @PostConstruct is executed just before the @Autowired? > Using pure Spring without Struts works well: running a JUnit test with my > @PostConstruct annotated method show myService is not null, but when this is > in a Struts action does not work... > > Has anybody see this behaviour? > > Thank you for your help! > > Emanuele > > Norris Shelton wrote: >> Did you set Spring to be your object factory in your struts.xml. If you >> used Spring annotations, did you annotate your bean to be injected with >> @Component and designate a base package for Spring to scan for beans? >> >> >> Norris Shelton >> Software Engineer >> Sun Certified Java 1.1 Programmer >> Shelton Consulting, LLC >> ICQ# 26487421 >> AIM NorrisEShelton >> YIM norrisshelton >> >> Is there a public myService setter? >> >> (I hardly even use annotations; maybe that's not necessary?) >> >> Dave >> >> >> >> >> From: "e_sli...@yahoo.it" >> To: user@struts.apache.org >> Sent: Monday, April 27, 2009 12:41:01 PM >> Subject: Autowired and PostConstruct with Struts + Spring >> >> Hello everybody! >> >> I'm trying to use my service into a Struts action but with no success. >> >> My struts action contains : >> >> @Autowired >> private MyService myService >> >> @PostConstruct >> public void init() { >> // use here myService >> } >> >> Unfortunately myService is always null and I cannot use myService in the >> init() method... >> >> The bean myService should correctly declared in my application-context.xml: >> >> >> ... >> >> >> and my struts.xml contains: >> >> >> Where I'm wrong? >> Many Thanks! >> >> Emanuele >> >> >> > > > > - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: Autowired and PostConstruct with Struts + Spring
Hi Norris and Dave! Thank you for your answers. Yes, I have get/set methods for myService. If you means declaring: in my struts.xml for my object factory, yes. I don't have @Component for Spring injection, but I suppose Spring work well as far as the myService bean is available in my context for other beans in my app. I'm just wondering about @Autowired and @PostConstruct behaviour when passing by Struts + Spring. Probably @PostConstruct is executed just before the @Autowired? Using pure Spring without Struts works well: running a JUnit test with my @PostConstruct annotated method show myService is not null, but when this is in a Struts action does not work... Has anybody see this behaviour? Thank you for your help! Emanuele Norris Shelton wrote: > Did you set Spring to be your object factory in your struts.xml. If you used > Spring annotations, did you annotate your bean to be injected with @Component > and designate a base package for Spring to scan for beans? > > > Norris Shelton > Software Engineer > Sun Certified Java 1.1 Programmer > Shelton Consulting, LLC > ICQ# 26487421 > AIM NorrisEShelton > YIM norrisshelton > > Is there a public myService setter? > > (I hardly even use annotations; maybe that's not necessary?) > > Dave > > > > > From: "e_sli...@yahoo.it" > To: user@struts.apache.org > Sent: Monday, April 27, 2009 12:41:01 PM > Subject: Autowired and PostConstruct with Struts + Spring > > Hello everybody! > > I'm trying to use my service into a Struts action but with no success. > > My struts action contains : > > @Autowired > private MyService myService > > @PostConstruct > public void init() { > // use here myService > } > > Unfortunately myService is always null and I cannot use myService in the > init() method... > > The bean myService should correctly declared in my application-context.xml: > > > ... > > > and my struts.xml contains: > > > Where I'm wrong? > Many Thanks! > > Emanuele > > >
Re: Autowired and PostConstruct with Struts + Spring
Did you set Spring to be your object factory in your struts.xml. If you used Spring annotations, did you annotate your bean to be injected with @Component and designate a base package for Spring to scan for beans? Norris Shelton Software Engineer Sun Certified Java 1.1 Programmer Shelton Consulting, LLC ICQ# 26487421 AIM NorrisEShelton YIM norrisshelton From: "e_sli...@yahoo.it" To: user@struts.apache.org Sent: Monday, April 27, 2009 12:41:01 PM Subject: Autowired and PostConstruct with Struts + Spring Hello everybody! I'm trying to use my service into a Struts action but with no success. My struts action contains : @Autowired private MyService myService @PostConstruct public void init() { // use here myService } Unfortunately myService is always null and I cannot use myService in the init() method... The bean myService should correctly declared in my application-context.xml: ... and my struts.xml contains: Where I'm wrong? Many Thanks! Emanuele
Re: Autowired and PostConstruct with Struts + Spring
e_sli...@yahoo.it wrote: Hello everybody! I'm trying to use my service into a Struts action but with no success. My struts action contains : @Autowired private MyService myService @PostConstruct public void init() { // use here myService } Unfortunately myService is always null and I cannot use myService in the init() method... The bean myService should correctly declared in my application-context.xml: ... and my struts.xml contains: Where I'm wrong? Is there a public myService setter? (I hardly even use annotations; maybe that's not necessary?) Dave - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Autowired and PostConstruct with Struts + Spring
Hello everybody! I'm trying to use my service into a Struts action but with no success. My struts action contains : @Autowired private MyService myService @PostConstruct public void init() { // use here myService } Unfortunately myService is always null and I cannot use myService in the init() method... The bean myService should correctly declared in my application-context.xml: ... and my struts.xml contains: Where I'm wrong? Many Thanks! Emanuele