Unable to instantiate Action, categoryAction, defined for 'category_queryJoinAccount' in namespace

来源:互联网 发布:上海离婚率数据 编辑:程序博客网 时间:2024/05/17 07:35
在开发过程中,突然遇到此问题,纠结了一下午,也没有结果,在网上搜的答案,基本上都没有出现,造成此问题的原因有很多,我遇到的原因只是其中之一,那么是什么错误造成此类问题,我的解决方案是什么呢,接下来奉上相关代码以及问题的解决:




<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>


<package name="myshop" extends="json-default" namespace="/">
<global-results>
<result name="aindex">/WEB-INF/main/aindex.jsp</result>
</global-results>

<global-allowed-methods>regex:.*</global-allowed-methods>

<action name="go_*_*" class="goAction">
<result name="go">/WEB-INF/{1}/{2}.jsp</result>
</action>

<action name="category_*" class="categoryAction" method="{1}">

<result name="jsonMap" type="json">
<param name="root">pageMap</param>
</result>

<result name="stream" type="stream">
<param name="inputName">inputStream</param>
</result>
</action>
</package>
</struts>




------------------------------------------------------------------


<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop" 
    xmlns:tx="http://www.springframework.org/schema/tx" 
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd">
       
   <!-- 扫描注解 -->
<context:component-scan base-package="it.fly"/>

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="com.mysql.jdbc.Driver"></property>
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/shop"/>
<property name="user" value="root"></property>
<property name="password" value="root"></property>
</bean>   

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
</bean>

<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>

<tx:advice id="advice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="*" propagation="SUPPORTS"/>
</tx:attributes>
</tx:advice>

<aop:config>
<aop:pointcut id="pointcut" expression="execution(* it.fly.service.impl.*.*(..))"/>
<aop:advisor advice-ref="advice" pointcut-ref="pointcut"/>
</aop:config>

   <bean id="goAction" class="it.fly.action.GoAction" scope="prototype">
   </bean>
   
   <bean id="categoryAction" class="it.fly.action.CategoryAction" scope="prototype"></bean>
   
   <bean id="accountAction" class="it.fly.action.AccountAction" scope="prototype"></bean>
</beans>


-------------------------------------------------------------------------
package it.fly.service.impl;


import org.springframework.stereotype.Service;


import it.fly.domain.Account;
import it.fly.service.AccountService;


/**
 * @author
 * @param <T>
 *
 */
public class AccountServiceImpl extends BaseServiceImpl<Account> implements AccountService{


}




---------------------------------------------------


1.大家应该有人发现serviceimpl代码有点问题,那么就是没有加service注解,
2.由于没有加注解,没有被spring扫描到,因此bean没有被spring的bean管理器加载出来。因为使用的是自动注入,所以action里边在注入的时候是找不到此service的。
3.再加上@service注解后,问题就解决了。




---------------------------------------------------
说明:此为本人第一篇博客,语言上的组织可能有问题,望大家见谅,会在以后的博客中慢慢改进,共同成长,共同进步
0 0
原创粉丝点击