[
https://issues.apache.org/jira/browse/WW-4215?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14056659#comment-14056659
]
Hudson commented on WW-4215:
----------------------------
SUCCESS: Integrated in Struts-JDK6-develop #57 (See
[https://builds.apache.org/job/Struts-JDK6-develop/57/])
WW-4215 Allows constructor injection (lukaszlenart: rev
ecab1b2b89ef8fe9c7174565e5193103ca98d9aa)
* plugins/cdi/src/main/java/org/apache/struts2/cdi/CdiObjectFactory.java
> 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)