请楼主贴出两个xml的<context:component-scan>配置看看

解决方案 »

  1.   

    spring-servlet.xml : 
    <?xml version="1.0" encoding="UTF-8"?>
      <beans xmlns="http://www.springframework.org/schema/beans"  
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"  
            xmlns:context="http://www.springframework.org/schema/context"  
    xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
     
      <context:annotation-config />
           <!-- 把标记了@Controller注解的类转换为bean -->  
          <context:component-scan base-package="com.xian" />  
      <!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 -->  
          <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />  
         
           <!-- 对模型视图名称的解析,即在模型视图名称添加前后缀  
           <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"  
              p:prefix="/WEB-INF/view/" p:suffix=".jsp" />  
             -->
           <bean id="multipartResolver"  
              class="org.springframework.web.multipart.commons.CommonsMultipartResolver"  
              p:defaultEncoding="utf-8" />  
               <!-- 开启Sping注释管理事务功能,指定事务管理的Bean -->
    <tx:annotation-driven transaction-manager="txManager" />
    <!-- end -->
      <!-- 关于返回页面的 -->  
        <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
        <property name="prefix" value="/jsp/" />  
        <property name="suffix" value=".jsp" />  
        </bean>  

     
     </beans>applicationContext.xml :
    <?xml version="1.0" encoding="UTF-8"?>
    <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-2.5.xsd
               http://www.springframework.org/schema/context
               http://www.springframework.org/schema/context/spring-context-2.5.xsd
               http://www.springframework.org/schema/tx 
               http://www.springframework.org/schema/tx/spring-tx-2.5.xsd 
               http://www.springframework.org/schema/aop 
               http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
    <!-- 开启切面代码 -->
    <aop:aspectj-autoproxy />
    <!-- end -->
       <!-- 读取jdbcInfo.properties配置文件-->
    <context:property-placeholder location="classpath:/jdbcInfo.properties" />

    <!-- 配置数据源 -->
    <bean id="dataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="${dataSource.driverClassName}" />
    <property name="url" value="${dataSource.url}" />
    <property name="username" value="${dataSource.username}" />
    <property name="password" value="${dataSource.password}" />
    </bean>

    <bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">${dataSource.dialect}</prop>
    <prop key="hibernate.hbm2ddl.auto">${dataSource.hbm2ddl.auto}</prop>
    <prop key="hibernate.hbm2ddl.auto">update</prop>
    </props>
    </property>
    <property name="packagesToScan">
    <list>
    <value>com.xian.domain</value><!-- 扫描实体类,也就是平时所说的model -->
    </list>
       </property>
    </bean>
     

    <bean id="txManager"
    class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
    <property name="dataSource" ref="dataSource" />
    </bean> 
    </beans> 
      

  2.   

    你的applicationContext.xml中没有指定<context:component-scan base-package="可以放到service层" />啊,意味着你所有的注解类未被装配到Spring容器,当然事务也没起作用。
      

  3.   

    <context:component-scan base-package="com.xian" />  
    这个配置不对。
    在spring-servlet.xml 中只扫描cotroller/action
    在applicationContext.xml :中扫描service/dao如果你只在controller里面扫描,事务很可能不起作用。因为现价值web context,后面再加载的spring context