Skip to content
Advertisement

Struts2.5.12 – NPE while using getText method from ActionSupport


I am migrating a project from Struts 2.3.3 to Struts 2.5.12 and I see NullPointerException when using the getText method from ActionSupport class.

My action class extends ActionSupport class. I have package.properties file also packaged in the war file.

My action class looks like:

public class MyAction extends ActionSupport {
    private List<String> months = new ArrayList<>(
            Arrays.asList(getText("date.month.default"), "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"));
}

And in package.properties file I have

date.month.default=MM

I see the below exception when the bean for my action class is instantiated. Does anyone know if I am doing anything wrong here?

ERROR DefaultDispatcherErrorHandler Exception occurred during processing request: Unable to instantiate Action, entryAction,  defined for 'entry' in namespace '/'Error creating bean with name 'entryAction' defined in "/D:/Software/JBossEAP/jboss-eap-7.0/bin/content/Member.war/WEB-INF/classes/my/company/member/web/action/entry/spring-context.xml": Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [my.company.member.web.action.entry.EntryAction]: Constructor threw exception; nested exception is java.lang.NullPointerException
 Unable to instantiate Action, entryAction,  defined for 'entry' in namespace '/'Error creating bean with name 'entryAction' defined in "/D:/Software/JBossEAP/jboss-eap-7.0/bin/content/Member.war/WEB-INF/classes/my/company/member/web/action/entry/spring-context.xml": Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [my.company.member.web.action.entry.EntryAction]: Constructor threw exception; nested exception is java.lang.NullPointerException - action - vfs:/D:/Software/JBossEAP/jboss-eap-7.0/bin/content/Member.war/WEB-INF/classes/struts-default.xml:133:44
    at com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:318)
    at com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:399)
    at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:204)
    at org.apache.struts2.factory.StrutsActionProxy.prepare(StrutsActionProxy.java:62)
    at org.apache.struts2.factory.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:37)
    at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
    at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:567)
    at org.apache.struts2.dispatcher.ExecuteOperations.executeAction(ExecuteOperations.java:81)
    at org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:143)
    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
    at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
    at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
    at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
    at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
    at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
    at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
    at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
    at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
    at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
    at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:285)
    at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:264)
    at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
    at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:175)
    at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)
    at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:792)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entryAction' defined in "/D:/Software/JBossEAP/jboss-eap-7.0/bin/content/Member.war/WEB-INF/classes/my/company/member/web/action/entry/spring-context.xml": Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [my.company.member.web.action.entry.EntryAction]: Constructor threw exception; nested exception is java.lang.NullPointerException
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:965)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:911)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1075)
    at com.opensymphony.xwork2.spring.SpringObjectFactory.buildBean(SpringObjectFactory.java:159)
    at com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:172)
    at com.opensymphony.xwork2.factory.DefaultActionFactory.buildAction(DefaultActionFactory.java:22)
    at com.opensymphony.xwork2.ObjectFactory.buildAction(ObjectFactory.java:137)
    at com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:299)
    ... 37 more
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [my.company.member.web.action.entry.EntryAction]: Constructor threw exception; nested exception is java.lang.NullPointerException
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:141)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:74)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:958)
    ... 48 more
Caused by: java.lang.NullPointerException
    at com.opensymphony.xwork2.ActionSupport.getTextProvider(ActionSupport.java:278)
    at com.opensymphony.xwork2.ActionSupport.getText(ActionSupport.java:83)
    at my.company.member.web.action.MyAction.<init>(MyAction.java:95)
    at my.company.member.web.action.entry.EntryAction.<init>(EntryAction.java:22)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:126)
    ... 50 more

The Project Structure is:
enter image description here

And the WAR built has structure as:
enter image description here

Below jar files are added to WEB-INF/lib in the WAR file:
classworlds-1.1.jar
com.springsource.org.aopalliance-1.0.0.jar
commons-betwixt-0.8.jar
commons-chain-1.2.jar
commons-digester-1.8.jar
commons-fileupload-1.2.1.jar
commons-httpclient-3.1.jar
commons-io-2.4.jar
commons-lang3-3.6.jar
commons-validator-1.3.1.jar
freemarker-2.3.23.jar
gson-2.1.jar
httpclient-4.3-beta1.jar
httpclient-osgi-4.3.jar
httpcore-4.2.2.jar
javassist-3.18.0-GA.jar
jaxrpc-api-1.1.jar
jcifs-1.3.17.jar
log4j-api-2.8.2.jar
ognl-3.1.12.jar
oro-2.0.8.jar
serializer-2.7.1.jar
spring-aop-3.0.5.RELEASE.jar
spring-asm-3.0.5.RELEASE.jar
spring-beans-3.0.5.RELEASE.jar
spring-context-3.0.5.RELEASE.jar
spring-context-support-3.0.5.RELEASE.jar
spring-core-3.0.5.RELEASE.jar
spring-expression-3.0.5.RELEASE.jar
spring-jdbc-3.0.5.RELEASE.jar
spring-jms-3.0.5.RELEASE.jar
spring-orm-3.0.5.RELEASE.jar
spring-remoting-2.0.8.jar
spring-tx-3.0.5.RELEASE.jar
spring-web-3.0.5.RELEASE.jar
struts2-core-2.5.12.jar
struts2-json-plugin-2.5.12.jar
struts2-spring-plugin-2.5.12.jar
struts2-tiles-plugin-2.5.12.jar
tiles-api-3.0.7.jar
tiles-autotag-core-runtime-1.2.jar
tiles-core-3.0.7.jar
tiles-el-3.0.7.jar
tiles-freemarker-3.0.7.jar
tiles-jsp-3.0.7.jar
tiles-ognl-3.0.7.jar
tiles-request-api-1.0.6.jar
tiles-request-freemarker-1.0.6.jar
tiles-request-jsp-1.0.6.jar
tiles-request-servlet-1.0.6.jar
tiles-servlet-3.0.7.jar
tiles-template-3.0.7.jar
wsdl4j-1.5.1.jar
xml-apis-1.3.02.jar

Advertisement

Answer

You should not use a file with name struts-default.xml. This is a configuration file that is loaded by default. The default configuration file name for the application is struts.xml.

Rename this file

struts-default.xml

to

struts.xml
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement