You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Alireza Fattahi <af...@yahoo.com.INVALID> on 2016/09/26 09:22:29 UTC

Struts 2 and Spring 4, how to get the validator or action object from spring application context

We are using Struts 2.5 and spring 4. The struts is configured spring as mentioned in https://struts.apache.org/docs/spring-and-struts-2.html.

The struts `actions` and `validators` are spring managed beans and I can `inject` ( or `autowire`) other beans in them.

This validator is working fine which shows the validator is an spring bean:

    public class MyValidator(){

        @javax.inject.Inject
        private HelperClass aHelperClass;
    }

Now, i want to get the `MyValidator` class from spring application context and use it. The below codes did not worked and returned null

    applicationContext.getBean("MyValidator");
    applicationContext.getBean("foo.bar.MyValidator");

I look at `applicationContext.getBeanDefinitionNames()` but could not find the `validator`.

So how can I get the struts validator from spring `applicationContext`

~Regards,
~~Alireza Fattahi
Struts 2 and Spring 4, how to get the validator or action object from spring application context

  
|  
|   
|   
|   |    |

   |

  |
|  
|   |  
Struts 2 and Spring 4, how to get the validator or action object from sprin...
 We are using Struts 2.5 and spring 4. The struts is configured spring as mentioned in https://struts.apache.org/...  |   |

  |

  |

 

Re: Struts 2 and Spring 4, how to get the validator or action object from spring application context

Posted by Lukasz Lenart <lu...@apache.org>.
2016-09-26 11:22 GMT+02:00 Alireza Fattahi <af...@yahoo.com.invalid>:
> We are using Struts 2.5 and spring 4. The struts is configured spring as mentioned in https://struts.apache.org/docs/spring-and-struts-2.html.
>
> The struts `actions` and `validators` are spring managed beans and I can `inject` ( or `autowire`) other beans in them.
>
> This validator is working fine which shows the validator is an spring bean:
>
>     public class MyValidator(){
>
>         @javax.inject.Inject
>         private HelperClass aHelperClass;
>     }
>
> Now, i want to get the `MyValidator` class from spring application context and use it. The below codes did not worked and returned null
>
>     applicationContext.getBean("MyValidator");
>     applicationContext.getBean("foo.bar.MyValidator");
>
> I look at `applicationContext.getBeanDefinitionNames()` but could not find the `validator`.
>
> So how can I get the struts validator from spring `applicationContext`

Annotated the validator with @Bean annotation?


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

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