gpt4 book ai didi

java - Struts2.5.12 - 使用 ActionSupport 中的 getText 方法时的 NPE

转载 作者:行者123 更新时间:2023-11-30 06:35:04 30 4
gpt4 key购买 nike


我正在将项目从 Struts 2.3.3 迁移到 Struts 2.5.12,并且在使用 ActionSupport 类中的 getText 方法时看到 NullPointerException

我的操作类扩展了 ActionSupport 类。我有 package.properties 文件也打包在 war 文件中。

我的 Action 类看起来像:

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"));
}

在 package.properties 文件中我有

date.month.default=MM

当我的操作类的 bean 被实例化时,我看到以下异常。有谁知道我在这里做错了什么吗?

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

项目结构是:
enter image description here

构建的 WAR 结构如下:
enter image description here

以下 jar 文件添加到 WAR 文件中的 WEB-INF/lib 中:
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
序列化器-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

最佳答案

您不应使用名为 struts-default.xml 的文件。这是默认加载的配置文件。应用程序的默认配置文件名为 struts.xml .

重命名该文件

struts-default.xml

struts.xml

关于java - Struts2.5.12 - 使用 ActionSupport 中的 getText 方法时的 NPE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45347478/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com