Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-4215

CDI plugin does not allow constructor injection

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.3.15.2
    • 2.3.20
    • Plugin - CDI
    • None

    Description

      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:

      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:
      

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

      public class MyCdiObjectFactory extends CdiObjectFactory {
      
          @Override
          public boolean isNoArgConstructorRequired() {
              return false;
          }
      }
      

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

      Attachments

        Activity

          People

            Unassigned Unassigned
            janssk1 gui
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: