You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "ASF subversion and git services (JIRA)" <ji...@apache.org> on 2014/07/09 21:19:05 UTC
[jira] [Commented] (WW-4215) CDI plugin does not allow constructor
injection
[ https://issues.apache.org/jira/browse/WW-4215?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14056630#comment-14056630 ]
ASF subversion and git services commented on WW-4215:
-----------------------------------------------------
Commit ecab1b2b89ef8fe9c7174565e5193103ca98d9aa in struts's branch refs/heads/develop from [~lukaszlenart]
[ https://git-wip-us.apache.org/repos/asf?p=struts.git;h=ecab1b2 ]
WW-4215 Allows constructor injection
> CDI plugin does not allow constructor injection
> -----------------------------------------------
>
> Key: WW-4215
> URL: https://issues.apache.org/jira/browse/WW-4215
> Project: Struts 2
> Issue Type: Improvement
> Components: Plugin - CDI
> Affects Versions: 2.3.15.2
> Reporter: gui
> Priority: Minor
> Fix For: 2.3.18
>
>
> 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.2#6252)