RE: Spring Injection Strange behaviour - SOLVED!

2015-09-06 Thread Martin Gainty
"Once you eliminate the impossible, whatever remains, no matter how improbable, 
must be the truth"Arthur Conan Doyle
You had to eliminate the other Tomcats as the cause

"Genius is one percent inspiration and ninety-nine percent perspiration." - 
Thomas A. Edison
Then you set out the hardwork to find where the auto-wiring is happening

By Doyles definition you have "good investigative technique"
By Edisons definition you are a genius

Congratulations Chris!
Martin  
__ 

  


> From: crisp...@gmx.us
> To: user@struts.apache.org
> CC: user@struts.apache.org
> Subject: Re: RE: Spring Injection Strange behaviour - SOLVED!
> Date: Sun, 6 Sep 2015 06:38:47 +0200
> 
> 
> Finally I found the root cause.
>  
> It seems I had some Spring jars of an earlier version in my Tomcat lib 
> directory on my dev machine, since I have more than one version of tomcat on 
> my system I was looking in the wrong instance of tomcat when I was trying 
> identify the cause. Sometimes I am such an idiot.
>  
> Thanks
>  
> Chris
>  
> 
> Sent: Sunday, September 06, 2015 at 3:32 AM
> From: Chris <crisp...@gmx.us>
> To: "Dave Newton" <davelnew...@gmail.com>, "Struts Users Mailing List" 
> <user@struts.apache.org>
> Subject: RE: Spring Injection Strange behaviour
> 
> Hi Dave,
>  
> Thanks for your reply.
>  
> I tried setting the scope of the action bean to prototype  (amoung 100 other 
> things) but it didn't change the behaviour.  I'm using Struts2 with Sping 
> plugin,  jdk1.8.0_51.
>  
> If it wasn't calling the setter that would make more sense, but sine it is 
> calling the setter that makes me beleive he autowiring is working, I just 
> can't understand why its later being set to null. I thought it might be a 
> scope issue but I don't know enough about struts to dig much deeper.
>  
> Thanks
>  
> Chris
>  
> -Original Message-
> From: Dave Newton [mailto:davelnew...@gmail.com]
> Sent: Saturday, September 5, 2015 11:27 PM
> To: Struts Users Mailing List
> Subject: Re: Spring Injection Strange behaviour
>  
> Not sure, but if nothing else the action should be set to `prototype` scope, 
> as they're instantiated per-request.
>  
> Are you using the Struts 2 Spring plugin?
>  
> On Sat, Sep 5, 2015 at 8:47 AM, Chris 
> <crisp...@gmx.us[mailto:crisp...@gmx.us]> wrote:
>  
> > I'm trying to use the Spring plugin to inject a dependency into my
> > action at runtime. This is the first time I've tried this with Struts2
> > so I may have missed something but I'm stumped because I can see the
> > dependency is injected but then the object is later null when I need
> > to use it. Here is my action class code:
> > 
> > public class UserRegisterAction extends ActionSupport {
> > private User user = new User();
> > 
> 
> -
> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
> For additional commands, e-mail: user-h...@struts.apache.org
>  
> 
> -
> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
> For additional commands, e-mail: user-h...@struts.apache.org
> 
  

RE: Spring Injection Strange behaviour

2015-09-05 Thread C N Davies
Hi Lukasz,

Thank you for your reply.

I defined my action like so:


http://struts.apache.org/dtds/struts-2.0.dtd;>



  

  
  
  confirmRegister.jsp
  /register.jsp
  /error.jsp
  
  


However this will throw an exception:

SEVERE: Dispatcher initialization failed
Unable to load configuration. - action - 
file:/D:/projects/BaseApp/out/artifacts/BaseApp_war_exploded/WEB-INF/classes/struts.xml:22:60
at 
com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:70)
at 
org.apache.struts2.dispatcher.Dispatcher.getContainer(Dispatcher.java:967)
at 
org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:435)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:479)
at 
org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:74)
at 
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:57)
at 
org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279)
at 
org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260)
at 
org.apache.catalina.core.ApplicationFilterConfig.(ApplicationFilterConfig.java:105)
at 
org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4841)
at 
org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5535)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at 
org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at 
org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
at 
org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1809)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

IntelliJ Idea reports that "class="UserRegisterAction" cannot be resolved and 
the only way to fix it is use the full class name.

I'm stumped!

Chris

-Original Message-
From: Lukasz Lenart [mailto:lukaszlen...@apache.org] 
Sent: Sunday, September 6, 2015 12:37 AM
To: Struts Users Mailing List
Subject: Re: Spring Injection Strange behaviour

How do you declare the action in struts.xml? Because instead full class name 
you must use the id from applicationContext.xml

http://struts.apache.org/dtds/struts-2.0.dtd;>



success.jsp




https://struts.apache.org/docs/spring-plugin.html#SpringPlugin-InitializingActionsfromSpring


Regards
--
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

2015-09-05 14:47 GMT+02:00 Chris <crisp...@gmx.us>:
> I'm trying to use the Spring plugin to inject a dependency into my action at 
> runtime. This is the first time I've tried this with Struts2 so I may have 
> missed something but I'm stumped because I can see the dependency is injected 
> but then the object is later null when I need to use it. Here is my action 
> class code:
>
> public class UserRegisterAction extends ActionSupport {
> private User user = new User();
>
> @Override
> public String execute(){
> getUserService().saveUser(user);
> return "success";
> }
>
> public UserServiceImpl getUserService(){
> return userService;
> }
>
> UserServiceImpl userService;
> public void setUserService(UserServiceImpl us){
> this.userService = us;
> }
> }
>
> Using the debugger I can see that upon startup "setUserService is called and 
> this.userService is set, so the injection appears to be working ok, but when 
> the execute method is called when the page is submitted userService is null. 
> I'm quite new to Struts but I don't understand how my userService is being 
> null.
>
> Can anyone see what I am missing?
>
>
> My applicationContext:
>
>
> 
>
> http://www.springframework.org/schema/beans;
>xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance; 
> xmlns:tx="http://www.springframework.org/schema/tx;
>xsi:schemaLocation="http://www.springframework.org/schema/beans 
> http://www.springframework.org/schema/beans/spring-beans.xsd
>http://www.springframework.org/schema/tx 
> http://www.springframework.org/schema/tx/spring-tx.xsd; 
> default-autowire="byName">
>
>  class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"
>  />
>
>  class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
>
>  class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBe

Re: Spring Injection Strange behaviour

2015-09-05 Thread Dave Newton
Not sure, but if nothing else the action should be set to `prototype`
scope, as they're instantiated per-request.

Are you using the Struts 2 Spring plugin?

On Sat, Sep 5, 2015 at 8:47 AM, Chris  wrote:

> I'm trying to use the Spring plugin to inject a dependency into my action
> at runtime. This is the first time I've tried this with Struts2 so I may
> have missed something but I'm stumped because I can see the dependency is
> injected but then the object is later null when I need to use it. Here is
> my action class code:
>
> public class UserRegisterAction extends ActionSupport {
> private User user = new User();
>
> @Override
> public String execute(){
> getUserService().saveUser(user);
> return "success";
> }
>
> public UserServiceImpl getUserService(){
> return userService;
> }
>
> UserServiceImpl userService;
> public void setUserService(UserServiceImpl us){
> this.userService = us;
> }
> }
>
> Using the debugger I can see that upon startup "setUserService is called
> and this.userService is set, so the injection appears to be working ok, but
> when the execute method is called when the page is submitted userService is
> null. I'm quite new to Struts but I don't understand how my userService is
> being null.
>
> Can anyone see what I am missing?
>
>
> My applicationContext:
>
>
> 
>
> http://www.springframework.org/schema/beans;
>xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance; xmlns:tx="
> http://www.springframework.org/schema/tx;
>xsi:schemaLocation="http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans.xsd
>http://www.springframework.org/schema/tx
> http://www.springframework.org/schema/tx/spring-tx.xsd;
> default-autowire="byName">
>
>  class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"
> />
>
>  class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
>
>  class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
> 
> 
>  class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
>  value="org.hibernate.dialect.MySQL5Dialect" />
> 
> 
> 
> 
> 
>
>  class="org.springframework.jdbc.datasource.DriverManagerDataSource">
> 
>  />
> 
> 
> 
>
>  class="org.springframework.orm.jpa.JpaTransactionManager">
> 
> 
>
> 
>
>  scope="prototype"/>
>
> 
> 
> 
>
> 
>
>
> Web.xml:
>
> 
> http://xmlns.jcp.org/xml/ns/javaee;
>  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance;
>  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
> http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd;
>  version="3.1">
>
>
> struts2
>
> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
> 
>
> 
> struts2
> /*
> 
>
> 
>
> org.springframework.web.context.ContextLoaderListener
> 
> 
>
>
> -
> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
> For additional commands, e-mail: user-h...@struts.apache.org
>
>


-- 
e: davelnew...@gmail.com
m: 908-380-8699
s: davelnewton_skype
t: @dave_newton 
b: Bucky Bits 
g: davelnewton 
so: Dave Newton 


Re: Spring Injection Strange behaviour

2015-09-05 Thread Lukasz Lenart
How do you declare the action in struts.xml? Because instead full
class name you must use the id from applicationContext.xml

http://struts.apache.org/dtds/struts-2.0.dtd;>



success.jsp




https://struts.apache.org/docs/spring-plugin.html#SpringPlugin-InitializingActionsfromSpring


Regards
-- 
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

2015-09-05 14:47 GMT+02:00 Chris :
> I'm trying to use the Spring plugin to inject a dependency into my action at 
> runtime. This is the first time I've tried this with Struts2 so I may have 
> missed something but I'm stumped because I can see the dependency is injected 
> but then the object is later null when I need to use it. Here is my action 
> class code:
>
> public class UserRegisterAction extends ActionSupport {
> private User user = new User();
>
> @Override
> public String execute(){
> getUserService().saveUser(user);
> return "success";
> }
>
> public UserServiceImpl getUserService(){
> return userService;
> }
>
> UserServiceImpl userService;
> public void setUserService(UserServiceImpl us){
> this.userService = us;
> }
> }
>
> Using the debugger I can see that upon startup "setUserService is called and 
> this.userService is set, so the injection appears to be working ok, but when 
> the execute method is called when the page is submitted userService is null. 
> I'm quite new to Struts but I don't understand how my userService is being 
> null.
>
> Can anyone see what I am missing?
>
>
> My applicationContext:
>
>
> 
>
> http://www.springframework.org/schema/beans;
>xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance; 
> xmlns:tx="http://www.springframework.org/schema/tx;
>xsi:schemaLocation="http://www.springframework.org/schema/beans 
> http://www.springframework.org/schema/beans/spring-beans.xsd
>http://www.springframework.org/schema/tx 
> http://www.springframework.org/schema/tx/spring-tx.xsd; 
> default-autowire="byName">
>
>  class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"
>  />
>
>  class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
>
>  class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
> 
> 
>  class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
>  value="org.hibernate.dialect.MySQL5Dialect" />
> 
> 
> 
> 
> 
>
>  class="org.springframework.jdbc.datasource.DriverManagerDataSource">
> 
> 
> 
> 
> 
>
>  class="org.springframework.orm.jpa.JpaTransactionManager">
> 
> 
>
> 
>
>  scope="prototype"/>
>
> 
> 
> 
>
> 
>
>
> Web.xml:
>
> 
> http://xmlns.jcp.org/xml/ns/javaee;
>  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance;
>  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
> http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd;
>  version="3.1">
>
>
> struts2
> 
> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
> 
>
> 
> struts2
> /*
> 
>
> 
> 
> org.springframework.web.context.ContextLoaderListener
> 
> 
>
>
> -
> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
> For additional commands, e-mail: user-h...@struts.apache.org
>

-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Re: RE: Spring Injection Strange behaviour - SOLVED!

2015-09-05 Thread Chris

Finally I found the root cause.
 
It seems I had some Spring jars of an earlier version in my Tomcat lib 
directory on my dev machine, since I have more than one version of tomcat on my 
system I was looking in the wrong instance of tomcat when I was trying identify 
the cause. Sometimes I am such an idiot.
 
Thanks
 
Chris
 

Sent: Sunday, September 06, 2015 at 3:32 AM
From: Chris <crisp...@gmx.us>
To: "Dave Newton" <davelnew...@gmail.com>, "Struts Users Mailing List" 
<user@struts.apache.org>
Subject: RE: Spring Injection Strange behaviour

Hi Dave,
 
Thanks for your reply.
 
I tried setting the scope of the action bean to prototype  (amoung 100 other 
things) but it didn't change the behaviour.  I'm using Struts2 with Sping 
plugin,  jdk1.8.0_51.
 
If it wasn't calling the setter that would make more sense, but sine it is 
calling the setter that makes me beleive he autowiring is working, I just can't 
understand why its later being set to null. I thought it might be a scope issue 
but I don't know enough about struts to dig much deeper.
 
Thanks
 
Chris
 
-Original Message-
From: Dave Newton [mailto:davelnew...@gmail.com]
Sent: Saturday, September 5, 2015 11:27 PM
To: Struts Users Mailing List
Subject: Re: Spring Injection Strange behaviour
 
Not sure, but if nothing else the action should be set to `prototype` scope, as 
they're instantiated per-request.
 
Are you using the Struts 2 Spring plugin?
 
On Sat, Sep 5, 2015 at 8:47 AM, Chris <crisp...@gmx.us[mailto:crisp...@gmx.us]> 
wrote:
 
> I'm trying to use the Spring plugin to inject a dependency into my
> action at runtime. This is the first time I've tried this with Struts2
> so I may have missed something but I'm stumped because I can see the
> dependency is injected but then the object is later null when I need
> to use it. Here is my action class code:
> 
> public class UserRegisterAction extends ActionSupport {
> private User user = new User();
> 

-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org
 

-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



RE: Spring Injection Strange behaviour

2015-09-05 Thread Chris


Hi Dave,
 
Thanks for your reply.
 
I tried setting the scope of the action bean to prototype  (amoung 100 other 
things) but it didn't change the behaviour.  I'm using Struts2 with Sping 
plugin,  jdk1.8.0_51.
 
If it wasn't calling the setter that would make more sense, but sine it is 
calling the setter that makes me beleive he autowiring is working, I just can't 
understand why its later being set to null. I thought it might be a scope issue 
but I don't know enough about struts to dig much deeper.
 
Thanks
 
Chris
 
-Original Message-
From: Dave Newton [mailto:davelnew...@gmail.com]
Sent: Saturday, September 5, 2015 11:27 PM
To: Struts Users Mailing List
Subject: Re: Spring Injection Strange behaviour
 
Not sure, but if nothing else the action should be set to `prototype` scope, as 
they're instantiated per-request.
 
Are you using the Struts 2 Spring plugin?
 
On Sat, Sep 5, 2015 at 8:47 AM, Chris <crisp...@gmx.us[mailto:crisp...@gmx.us]> 
wrote:
 
> I'm trying to use the Spring plugin to inject a dependency into my
> action at runtime. This is the first time I've tried this with Struts2
> so I may have missed something but I'm stumped because I can see the
> dependency is injected but then the object is later null when I need
> to use it. Here is my action class code:
> 
> public class UserRegisterAction extends ActionSupport {
> private User user = new User();
> 

-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org