You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "Brad Cupit (JIRA)" <ji...@apache.org> on 2008/03/18 23:01:58 UTC

[jira] Created: (WW-2558) Spring plugin can't find Action classes configured by Spring 2.5 annotations

Spring plugin can't find Action classes configured by Spring 2.5 annotations
----------------------------------------------------------------------------

                 Key: WW-2558
                 URL: https://issues.apache.org/struts/browse/WW-2558
             Project: Struts 2
          Issue Type: Bug
          Components: Plugin - Spring
    Affects Versions: 2.0.11.1
            Reporter: Brad Cupit
            Priority: Minor


The Spring plugin looks up Spring beans based on the fully qualified class name, and doesn't find Spring-managed Action classes configured by Spring annotations. (Spring 2.5 can automatically find annotated beans instead of using xml config). These annotated beans have short bean names, meaning "object" instead of java.lang.Object

Instead, the Spring plugin instantiates the bean itself and follows the autowire policy, but the bean is not managed by Spring.

Ultimate Goal:
Be able to use the Spring annotation config and the Struts Codebehind plugin to eliminate xml configuration in Struts and Spring, and yet still have Actions be fully Spring managed.

There are three current workarounds:
1) let the Spring plugin instantiate and autowire Actions as it does now, but can't use any AOP features for those Actions
2) configure the bean in struts.xml and provide the 'short' bean name as the class name
3) configure the bean in a spring xml file and don't specify an id (the default id is the fully qualified class name)

None of these workarounds provide the ultimate goal of zero xml configuration and full Spring integration.

Proposed fix:
Alter the Spring plugin to lookup the bean based on type instead of using the class as the bean name. It could use ListableBeanFactory#getBeansOfType(), and throw an exception if there is more than one bean for that Action class. This could be configurable by a Struts constant (like "struts.objectFactory.spring.lookup" whose values could be "byClass" or "byName"). The changes could go in SpringObjectFactory#buildBean(String, Map, boolean)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (WW-2558) Spring plugin can't find Action classes configured by Spring 2.5 annotations

Posted by "Brad Cupit (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/struts/browse/WW-2558?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=43525#action_43525 ] 

bradcupit edited comment on WW-2558 at 3/20/08 1:13 PM:
---------------------------------------------------------

I have found a 4th workaround, which actually solves the problem nicely:

<context:component-scan name-generator="edu.lsu.SomeClassBeanNameGenerator" base-package="..."/>

The name-generator attribute of component-scan takes a class which implements BeanNameGenerator. The easiest way to write this class is to extend AnnotationBeanNameGenerator and override buildDefaultBeanName(..) so that it returns beanDefinition.getBeanClassName(). This class only has one method which is exactly one line long  :-)

This workaround permits the ultimate goal of having Struts Actions be fully managed by Spring and yet no xml configuration for individual Struts or Spring beans.

I've reduced this issue to Improvement and Trivial as a result of finding this workaround. If it never gets fixed we would still be just fine.

      was (Author: bradcupit):
    I have found a 4th workaround, which is actually solves the problem nicely:

<context:component-scan name-generator="edu.lsu.SomeClassBeanNameGenerator" base-package="..."/>

The name-generator attribute of component-scan takes a class which implements BeanNameGenerator. The easiest way to write this class is to extend AnnotationBeanNameGenerator and override buildDefaultBeanName so that it returns the beanClassName. This class would only have one method which is exactly one line long  :-)

This workaround permits the ultimate goal of having Struts Actions be fully managed by Spring and yet no xml configuration for individual Struts or Spring beans.

I've reduced this issue to Improvement and Trivial as a result of finding this workaround. If it never gets fixed we would still be just fine.
  
> Spring plugin can't find Action classes configured by Spring 2.5 annotations
> ----------------------------------------------------------------------------
>
>                 Key: WW-2558
>                 URL: https://issues.apache.org/struts/browse/WW-2558
>             Project: Struts 2
>          Issue Type: Improvement
>          Components: Plugin - Spring
>    Affects Versions: 2.0.11.1
>            Reporter: Brad Cupit
>            Priority: Trivial
>
> The Spring plugin looks up Spring beans based on the fully qualified class name, and doesn't find Spring-managed Action classes configured by Spring annotations. (Spring 2.5 can automatically find annotated beans instead of using xml config). These annotated beans have short bean names, meaning "object" instead of java.lang.Object
> Instead, the Spring plugin instantiates the bean itself and follows the autowire policy, but the bean is not managed by Spring.
> Ultimate Goal:
> Be able to use the Spring annotation config and the Struts Codebehind plugin to eliminate xml configuration in Struts and Spring, and yet still have Actions be fully Spring managed.
> There are three current workarounds:
> 1) let the Spring plugin instantiate and autowire Actions as it does now, but can't use any AOP features for those Actions
> 2) configure the bean in struts.xml and provide the 'short' bean name as the class name
> 3) configure the bean in a spring xml file and don't specify an id (the default id is the fully qualified class name)
> None of these workarounds provide the ultimate goal of zero xml configuration and full Spring integration.
> Proposed fix:
> Alter the Spring plugin to lookup the bean based on type instead of using the class as the bean name. It could use ListableBeanFactory#getBeansOfType(), and throw an exception if there is more than one bean for that Action class. This could be configurable by a Struts constant (like "struts.objectFactory.spring.lookup" whose values could be "byClass" or "byName"). The changes could go in SpringObjectFactory#buildBean(String, Map, boolean)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (WW-2558) Spring plugin can't find Action classes configured by Spring 2.5 annotations

Posted by "Musachy Barroso (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/struts/browse/WW-2558?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Musachy Barroso resolved WW-2558.
---------------------------------

    Resolution: Won't Fix

I don't think what you said is a workaround at all, but the way it should be, IMO.

> Spring plugin can't find Action classes configured by Spring 2.5 annotations
> ----------------------------------------------------------------------------
>
>                 Key: WW-2558
>                 URL: https://issues.apache.org/struts/browse/WW-2558
>             Project: Struts 2
>          Issue Type: Improvement
>          Components: Plugin - Spring
>    Affects Versions: 2.0.11.1
>            Reporter: Brad Cupit
>            Priority: Trivial
>             Fix For: 2.2.x
>
>
> The Spring plugin looks up Spring beans based on the fully qualified class name, and doesn't find Spring-managed Action classes configured by Spring annotations. (Spring 2.5 can automatically find annotated beans instead of using xml config). These annotated beans have short bean names, meaning "object" instead of java.lang.Object
> Instead, the Spring plugin instantiates the bean itself and follows the autowire policy, but the bean is not managed by Spring.
> Ultimate Goal:
> Be able to use the Spring annotation config and the Struts Codebehind plugin to eliminate xml configuration in Struts and Spring, and yet still have Actions be fully Spring managed.
> There are three current workarounds:
> 1) let the Spring plugin instantiate and autowire Actions as it does now, but can't use any AOP features for those Actions
> 2) configure the bean in struts.xml and provide the 'short' bean name as the class name
> 3) configure the bean in a spring xml file and don't specify an id (the default id is the fully qualified class name)
> None of these workarounds provide the ultimate goal of zero xml configuration and full Spring integration.
> Proposed fix:
> Alter the Spring plugin to lookup the bean based on type instead of using the class as the bean name. It could use ListableBeanFactory#getBeansOfType(), and throw an exception if there is more than one bean for that Action class. This could be configurable by a Struts constant (like "struts.objectFactory.spring.lookup" whose values could be "byClass" or "byName"). The changes could go in SpringObjectFactory#buildBean(String, Map, boolean)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (WW-2558) Spring plugin can't find Action classes configured by Spring 2.5 annotations

Posted by "Brad Cupit (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/struts/browse/WW-2558?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=43525#action_43525 ] 

bradcupit edited comment on WW-2558 at 3/24/08 9:55 AM:
---------------------------------------------------------

I have found a 4th workaround, which actually solves the problem nicely. It involves extending a Spring class and altering some Spring configuration (no Struts changes though). For informational purposes, here's the solution:

in your Spring xml config file:
<context:component-scan name-generator="edu.lsu.SomeClassBeanNameGenerator" base-package="..."/>

The name-generator attribute of component-scan takes a class which implements BeanNameGenerator. The easiest way to write this class is to extend AnnotationBeanNameGenerator and override buildDefaultBeanName(..) so that it returns beanDefinition.getBeanClassName(). This class only has one method which is exactly one line long  :-)

This workaround permits the ultimate goal of having Struts Actions be fully managed by Spring and yet no xml configuration for individual Struts or Spring beans.

One final note when using Spring and Struts2 together like this: your Spring beans will need to be 'prototype' scope and not 'singleton' scope (the default), since Struts 2 will set request-specific properties on Action objects. See Spring's @Scope annotation or  <context:component-scan scope-resolver="your.custom.scope.resolver.Here">

I've reduced this issue to Improvement and Trivial as a result of finding this workaround. If it never gets fixed we would still be just fine.

      was (Author: bradcupit):
    I have found a 4th workaround, which actually solves the problem nicely. It involves extending a Spring class and altering some Spring configuration (no Struts changes though). For informational purposes, here's the solution:

in your Spring xml config file:
<context:component-scan name-generator="edu.lsu.SomeClassBeanNameGenerator" base-package="..."/>

The name-generator attribute of component-scan takes a class which implements BeanNameGenerator. The easiest way to write this class is to extend AnnotationBeanNameGenerator and override buildDefaultBeanName(..) so that it returns beanDefinition.getBeanClassName(). This class only has one method which is exactly one line long  :-)

This workaround permits the ultimate goal of having Struts Actions be fully managed by Spring and yet no xml configuration for individual Struts or Spring beans.

I've reduced this issue to Improvement and Trivial as a result of finding this workaround. If it never gets fixed we would still be just fine.
  
> Spring plugin can't find Action classes configured by Spring 2.5 annotations
> ----------------------------------------------------------------------------
>
>                 Key: WW-2558
>                 URL: https://issues.apache.org/struts/browse/WW-2558
>             Project: Struts 2
>          Issue Type: Improvement
>          Components: Plugin - Spring
>    Affects Versions: 2.0.11.1
>            Reporter: Brad Cupit
>            Priority: Trivial
>
> The Spring plugin looks up Spring beans based on the fully qualified class name, and doesn't find Spring-managed Action classes configured by Spring annotations. (Spring 2.5 can automatically find annotated beans instead of using xml config). These annotated beans have short bean names, meaning "object" instead of java.lang.Object
> Instead, the Spring plugin instantiates the bean itself and follows the autowire policy, but the bean is not managed by Spring.
> Ultimate Goal:
> Be able to use the Spring annotation config and the Struts Codebehind plugin to eliminate xml configuration in Struts and Spring, and yet still have Actions be fully Spring managed.
> There are three current workarounds:
> 1) let the Spring plugin instantiate and autowire Actions as it does now, but can't use any AOP features for those Actions
> 2) configure the bean in struts.xml and provide the 'short' bean name as the class name
> 3) configure the bean in a spring xml file and don't specify an id (the default id is the fully qualified class name)
> None of these workarounds provide the ultimate goal of zero xml configuration and full Spring integration.
> Proposed fix:
> Alter the Spring plugin to lookup the bean based on type instead of using the class as the bean name. It could use ListableBeanFactory#getBeansOfType(), and throw an exception if there is more than one bean for that Action class. This could be configurable by a Struts constant (like "struts.objectFactory.spring.lookup" whose values could be "byClass" or "byName"). The changes could go in SpringObjectFactory#buildBean(String, Map, boolean)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (WW-2558) Spring plugin can't find Action classes configured by Spring 2.5 annotations

Posted by "Don Brown (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/struts/browse/WW-2558?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Don Brown updated WW-2558:
--------------------------

    Fix Version/s: 2.2.x

> Spring plugin can't find Action classes configured by Spring 2.5 annotations
> ----------------------------------------------------------------------------
>
>                 Key: WW-2558
>                 URL: https://issues.apache.org/struts/browse/WW-2558
>             Project: Struts 2
>          Issue Type: Improvement
>          Components: Plugin - Spring
>    Affects Versions: 2.0.11.1
>            Reporter: Brad Cupit
>            Priority: Trivial
>             Fix For: 2.2.x
>
>
> The Spring plugin looks up Spring beans based on the fully qualified class name, and doesn't find Spring-managed Action classes configured by Spring annotations. (Spring 2.5 can automatically find annotated beans instead of using xml config). These annotated beans have short bean names, meaning "object" instead of java.lang.Object
> Instead, the Spring plugin instantiates the bean itself and follows the autowire policy, but the bean is not managed by Spring.
> Ultimate Goal:
> Be able to use the Spring annotation config and the Struts Codebehind plugin to eliminate xml configuration in Struts and Spring, and yet still have Actions be fully Spring managed.
> There are three current workarounds:
> 1) let the Spring plugin instantiate and autowire Actions as it does now, but can't use any AOP features for those Actions
> 2) configure the bean in struts.xml and provide the 'short' bean name as the class name
> 3) configure the bean in a spring xml file and don't specify an id (the default id is the fully qualified class name)
> None of these workarounds provide the ultimate goal of zero xml configuration and full Spring integration.
> Proposed fix:
> Alter the Spring plugin to lookup the bean based on type instead of using the class as the bean name. It could use ListableBeanFactory#getBeansOfType(), and throw an exception if there is more than one bean for that Action class. This could be configurable by a Struts constant (like "struts.objectFactory.spring.lookup" whose values could be "byClass" or "byName"). The changes could go in SpringObjectFactory#buildBean(String, Map, boolean)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (WW-2558) Spring plugin can't find Action classes configured by Spring 2.5 annotations

Posted by "Brad Cupit (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/struts/browse/WW-2558?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Brad Cupit updated WW-2558:
---------------------------

      Priority: Trivial  (was: Minor)
    Issue Type: Improvement  (was: Bug)

I have found a 4th workaround, which is actually solves the problem nicely:

<context:component-scan name-generator="edu.lsu.SomeClassBeanNameGenerator" base-package="..."/>

The name-generator attribute of component-scan takes a class which implements BeanNameGenerator. The easiest way to write this class is to extend AnnotationBeanNameGenerator and override buildDefaultBeanName so that it returns the beanClassName. This class would only have one method which is exactly one line long  :-)

This workaround permits the ultimate goal of having Struts Actions be fully managed by Spring and yet no xml configuration for individual Struts or Spring beans.

I've reduced this issue to Improvement and Trivial as a result of finding this workaround. If it never gets fixed we would still be just fine.

> Spring plugin can't find Action classes configured by Spring 2.5 annotations
> ----------------------------------------------------------------------------
>
>                 Key: WW-2558
>                 URL: https://issues.apache.org/struts/browse/WW-2558
>             Project: Struts 2
>          Issue Type: Improvement
>          Components: Plugin - Spring
>    Affects Versions: 2.0.11.1
>            Reporter: Brad Cupit
>            Priority: Trivial
>
> The Spring plugin looks up Spring beans based on the fully qualified class name, and doesn't find Spring-managed Action classes configured by Spring annotations. (Spring 2.5 can automatically find annotated beans instead of using xml config). These annotated beans have short bean names, meaning "object" instead of java.lang.Object
> Instead, the Spring plugin instantiates the bean itself and follows the autowire policy, but the bean is not managed by Spring.
> Ultimate Goal:
> Be able to use the Spring annotation config and the Struts Codebehind plugin to eliminate xml configuration in Struts and Spring, and yet still have Actions be fully Spring managed.
> There are three current workarounds:
> 1) let the Spring plugin instantiate and autowire Actions as it does now, but can't use any AOP features for those Actions
> 2) configure the bean in struts.xml and provide the 'short' bean name as the class name
> 3) configure the bean in a spring xml file and don't specify an id (the default id is the fully qualified class name)
> None of these workarounds provide the ultimate goal of zero xml configuration and full Spring integration.
> Proposed fix:
> Alter the Spring plugin to lookup the bean based on type instead of using the class as the bean name. It could use ListableBeanFactory#getBeansOfType(), and throw an exception if there is more than one bean for that Action class. This could be configurable by a Struts constant (like "struts.objectFactory.spring.lookup" whose values could be "byClass" or "byName"). The changes could go in SpringObjectFactory#buildBean(String, Map, boolean)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (WW-2558) Spring plugin can't find Action classes configured by Spring 2.5 annotations

Posted by "Brad Cupit (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/struts/browse/WW-2558?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=43525#action_43525 ] 

bradcupit edited comment on WW-2558 at 3/24/08 8:19 AM:
---------------------------------------------------------

I have found a 4th workaround, which actually solves the problem nicely. It involves extending a Spring class and altering some Spring configuration (no Struts changes though). For informational purposes, here's the solution:

in your Spring xml config file:
<context:component-scan name-generator="edu.lsu.SomeClassBeanNameGenerator" base-package="..."/>

The name-generator attribute of component-scan takes a class which implements BeanNameGenerator. The easiest way to write this class is to extend AnnotationBeanNameGenerator and override buildDefaultBeanName(..) so that it returns beanDefinition.getBeanClassName(). This class only has one method which is exactly one line long  :-)

This workaround permits the ultimate goal of having Struts Actions be fully managed by Spring and yet no xml configuration for individual Struts or Spring beans.

I've reduced this issue to Improvement and Trivial as a result of finding this workaround. If it never gets fixed we would still be just fine.

      was (Author: bradcupit):
    I have found a 4th workaround, which actually solves the problem nicely:

<context:component-scan name-generator="edu.lsu.SomeClassBeanNameGenerator" base-package="..."/>

The name-generator attribute of component-scan takes a class which implements BeanNameGenerator. The easiest way to write this class is to extend AnnotationBeanNameGenerator and override buildDefaultBeanName(..) so that it returns beanDefinition.getBeanClassName(). This class only has one method which is exactly one line long  :-)

This workaround permits the ultimate goal of having Struts Actions be fully managed by Spring and yet no xml configuration for individual Struts or Spring beans.

I've reduced this issue to Improvement and Trivial as a result of finding this workaround. If it never gets fixed we would still be just fine.
  
> Spring plugin can't find Action classes configured by Spring 2.5 annotations
> ----------------------------------------------------------------------------
>
>                 Key: WW-2558
>                 URL: https://issues.apache.org/struts/browse/WW-2558
>             Project: Struts 2
>          Issue Type: Improvement
>          Components: Plugin - Spring
>    Affects Versions: 2.0.11.1
>            Reporter: Brad Cupit
>            Priority: Trivial
>
> The Spring plugin looks up Spring beans based on the fully qualified class name, and doesn't find Spring-managed Action classes configured by Spring annotations. (Spring 2.5 can automatically find annotated beans instead of using xml config). These annotated beans have short bean names, meaning "object" instead of java.lang.Object
> Instead, the Spring plugin instantiates the bean itself and follows the autowire policy, but the bean is not managed by Spring.
> Ultimate Goal:
> Be able to use the Spring annotation config and the Struts Codebehind plugin to eliminate xml configuration in Struts and Spring, and yet still have Actions be fully Spring managed.
> There are three current workarounds:
> 1) let the Spring plugin instantiate and autowire Actions as it does now, but can't use any AOP features for those Actions
> 2) configure the bean in struts.xml and provide the 'short' bean name as the class name
> 3) configure the bean in a spring xml file and don't specify an id (the default id is the fully qualified class name)
> None of these workarounds provide the ultimate goal of zero xml configuration and full Spring integration.
> Proposed fix:
> Alter the Spring plugin to lookup the bean based on type instead of using the class as the bean name. It could use ListableBeanFactory#getBeansOfType(), and throw an exception if there is more than one bean for that Action class. This could be configurable by a Struts constant (like "struts.objectFactory.spring.lookup" whose values could be "byClass" or "byName"). The changes could go in SpringObjectFactory#buildBean(String, Map, boolean)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.