struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "gui (JIRA)" <j...@apache.org>
Subject [jira] [Created] (WW-4215) CDI plugin does not allow constructor injection
Date Thu, 03 Oct 2013 08:20:41 GMT
gui created WW-4215:
-----------------------

             Summary: CDI plugin does not allow constructor injection
                 Key: WW-4215
                 URL: https://issues.apache.org/jira/browse/WW-4215
             Project: Struts 2
          Issue Type: Bug
          Components: Plugin - CDI
    Affects Versions: 2.3.15.2
            Reporter: gui


I'm converting some actions from spring injection to CDI injection. 
The beans have a non empty constructor that can be used by CDI (constructor is annotated with
@Inject). I don't want to switch to field injection, since i like to use final fields for
dependencies that don't change. 

However, cdi-plugin insists on having a no-arg constructor: 

{code}
Caused by: Action class [com.mycompany.MyClass] does not have a public no-arg constructor
- action - file:/struts.xml:22:106
        at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.verifyAction(XmlConfigurationProvider.java:431)
[xwork-core-2.3
.1.jar:2.3.1]
        at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurationProvider.java:370)
[xwork-core-2.3.1.
jar:2.3.1]
        at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:487)
[xwork-core-2.3.1
.jar:2.3.1]
        at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigurationProvider.java:278)
[xwork-core-2.3
.1.jar:2.3.1]
        at org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(StrutsXmlConfigurationProvider.java:112)
[struts2-core-2.3.
1.jar:2.3.1]
        at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:204)
[xwork-core-2.3.1.jar:2.3
.1]
        at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:
{code}


After looking at the code, i created my own ObjectFactory that overrides the 'isNoArgConstructorRequired'
method. 

{code}
public class MyCdiObjectFactory extends CdiObjectFactory {

    @Override
    public boolean isNoArgConstructorRequired() {
        return false;
    }
}
{code}

Using this objectfactory, all works as expected. It would be good to have this in the standard
CidObjectFactory.



--
This message was sent by Atlassian JIRA
(v6.1#6144)

Mime
View raw message