执行操作时AnnotationValidationInterceptor抛出NoSuchMethodException [英] NoSuchMethodException thrown by AnnotationValidationInterceptor when executing an action
问题描述
所用罐子的详细信息: Struts2 2.2.1 春天3.0.5.RELEASE 休眠3.6.0.FINAL
Details of jars used: Struts2 2.2.1 Spring 3.0.5.RELEASE Hibernate 3.6.0.FINAL
尝试执行如下所示的操作时,我遇到一个奇怪的问题:
I am experiencing a strange issue when trying to execute an action mapped as follows:
<action name="supplierSearch" class="supplierSearchAction">
<result>/pages/suppliersearch.jsp</result>
</action>
<action name="searchForSupplier" class="supplierSearchAction" method="doSearch">
<result>/pages/suppliersearch.jsp</result>
</action>
第一个动作将用户带到搜索页面,他们输入搜索字符串,然后在发布表单时调用第二个动作.
the first action sends the user to a search page, they enter a search string and then the second action is invoked when the post the form.
spring config中的操作如下:
The action in spring config is as follows:
<bean id="supplierSearchAction"
class="com.blah.SupplierSearchAction"
scope="prototype">
<property name="searchService" ref="supplierSearchService"></property>
</bean>
搜索服务使用休眠搜索,其定义如下:
the search service uses hibernate search and is defined as follows:
<bean id="supplierSearchService"
class="com.devcentre.yubi.application.service.SupplierSearchServiceImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
我正在使用spring aop来配置事务边界,而持久性配置如下:
I am using spring aop to configure my transaction boundaries and the persistence config is as follows:
<tx:annotation-driven transaction-manager="txManager" />
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
// annotated classes here
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect"> org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">upgrade</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.provider_class">
net.sf.ehcache.hibernate.SingletonEhCacheProvider</prop>
<prop key="hibernate.search.default.directory_provider">org.hibernate.search.store.FSDirectoryProvider
</prop>
<prop key="hibernate.search.default.indexBase">/lucene/indexes</prop>
<prop key="hibernate.search.default.batch.merge_factor">10</prop>
<prop key="hibernate.search.default.batch.max_buffered_docs">10</prop>
</props>
</property>
</bean>
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
在我的web.xml中,Spring的配置如下:
Spring is configured as follows in my web.xml:
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/src/spring-config.xml
/WEB-INF/src/persistence-config.xml
</param-value>
</context-param>
在搜索JSP页面上,我有一个表单,该表单将搜索字符串提交给应该调用doSearch方法的操作.但是,当我提交搜索时,出现如下异常(因为启用了devmode):
On the search JSP page I have a form which submits the search string to the action which should invoke the doSearch method. However, when I submit the search I get an exception as follows (because devmode is enabled):
Struts has detected an unhandled exception:
Messages: $Proxy28.doSearch()
File: java/lang/Class.java Line
number: 1,605
然后是堆栈跟踪:
java.lang.NoSuchMethodException: $Proxy28.addComponent()
java.lang.Class.getMethod(Class.java:1605)
org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.getActionMethod(AnnotationValidationInterceptor.java:75)
org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:47)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
这很奇怪,因为操作类上有一个带有签名的方法:
This is very odd because there is a method on the action class with the signature:
public String doSearch()
任何人都可以帮助您了解为什么ActionProxy没有所需的方法吗?
Can anyone help shed light on why the ActionProxy doesn't have the expected method?
谢谢
亚历克斯
推荐答案
java.lang.NoSuchMethodException: $Proxy25.doSearch()
请注意,您的操作类的名称为 $ Proxy25 .似乎正在为您的动作类创建动态代理.在类的方法上使用面向方面编程(AOP)的方法拦截器时,通常会看到这种情况.例如用于交易之类的东西.
Notice that the name of your action class is $Proxy25. It appears that something is creating a dynamic proxy to your action class. This is usually seen when using Aspect Oriented Programming (AOP) method interceptors on methods of a class — e.g., for things like transactions.
例如,我经常使用Google Guice,并且在类的方法上使用AOP方法拦截器时,称为LoginAction
的操作将创建一个名为LoginAction$$EnhancerByGuice$$someAdditionalCharacters
的动态代理. 虽然此动态代理对类的方法进行了子类化,但它不继承注释.我的猜测是,这里发生了相同的事情.
For example, I use Google Guice from time-to-time and when using AOP method interceptors on methods of a class, an action called LoginAction
would have a dynamic proxy created called LoginAction$$EnhancerByGuice$$someAdditionalCharacters
. While this dynamic proxy subclasses the methods of the class, it does not inherit annotations. My guess is that the same thing is happening here.
我不使用Spring,所以我不熟悉它用于创建动态代理的库.
I don't use Spring, so I am not familiar with what libraries it uses to create dynamic proxies.
更新
如果从操作类中删除AOP批注,则它应能按预期工作.您的操作类可以委派给服务层类,以处理对数据库的持久性(您可以在该类的方法上放置@Transactional
批注).
If you remove the AOP annotations from your action class, then it should work as expected. Your action class can delegate to a service-layer class to handle persisting to the database (you can put the @Transactional
annotation on that class's method(s)).
这篇关于执行操作时AnnotationValidationInterceptor抛出NoSuchMethodException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!