在web中必须在web.xml中进行配置好spring,然后在applicationContext.xml中配置上aop事务,这很明显和在junit中不一样。不能直接放入web程序的。

解决方案 »

  1.   

    我已经全部配置好了<?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.5" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <listener>  
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
    </listener>  
    <context-param>  
    <param-name>contextConfigLocation</param-name>  
    <param-value>classpath:applicationContext.xml</param-value>  
    </context-param>  
    <servlet>  
    <servlet-name>springmvc</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
    <init-param>  
    <param-name>contextConfigLocation</param-name>  
    <param-value>classpath:spring-servlet.xml</param-value>  
    </init-param>
    <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>  
    <servlet-name>springmvc</servlet-name>  
    <url-pattern>*.do</url-pattern>
    </servlet-mapping>

      <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
      </welcome-file-list>
    </web-app> <!-- 启动扫描所有的controller -->
        <context:component-scan base-package="com.cloud.cn"/>
        
        <context:annotation-config/>
        
    <!-- 开启aop注解  -->
    <aop:aspectj-autoproxy/>项目 也启动了,但是就是aop没有织入
    在applicationContext里面配置<aop:config>
        <aop:pointcut id="servicePointcut" expression="execution(* com..*.product.action.*.*(..))"/>
        <!-- 切面 -->
            <aop:aspect id="myAop" ref="beforeAdvice">
                <!-- 执行的切面方法 -->
                <aop:before method="beforeLogin" pointcut-ref="servicePointcut" />
            </aop:aspect>
      </aop:config>
    这样程序可以织入before,但是我想用注解,不用shema配置
      

  2.   

    有人解释下注解模式的aop配置么