@Aspect注解不生效!

Old-Summer 2015-05-10 05:46:59
<?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:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.1.xsd">

<!-- 启动@AspectJ支持 -->
<aop:aspectj-autoproxy/>

<!-- 设置自动搜索目录 -->
<context:component-scan base-package="com.gmc"/>

<!-- 事务管理器配置,单数据源事务 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>

<!-- 使用annotation定义事务 -->
<tx:annotation-driven transaction-manager="transactionManager"/>

<!-- 定义数据源Bean,使用C3P0数据源实现,并注入数据源的必要信息 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close"
p:driverClass="com.mysql.jdbc.Driver"
p:jdbcUrl="jdbc:mysql://127.0.0.1:3306/gmc"
p:user="root"
p:password="root"
p:maxPoolSize="40"
p:minPoolSize="2"
p:initialPoolSize="2"
p:maxIdleTime="30"/>

<!-- 定义Hibernate的SessionFactory,SessionFactory需要依赖数据源,注入dataSource -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" p:dataSource-ref="dataSource">
<!-- annotatedClasses用来列出全部持久化类 -->
<property name="annotatedClasses">
<list>
<!-- 以下用来列出所有的PO类-->
<value>com.gmc.entity.User</value>
<value>com.gmc.entity.Article</value>
</list>
</property>
<!-- 定义Hibernate SessionFactory的属性 -->
<property name="hibernateProperties">
<props>
<!-- 指定Hibernate的连接方言 -->
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
<!--是否根据Hiberante映射创建数据表 -->
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
</props>
</property>

</bean>



</beans>




package com.gmc.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;


@Aspect
@Component
public class LogAspect {


@Pointcut("execution(* com.gmc.service*.*(..))")
public void myPointCut(){}



@Before("LogAspect.myPointCut()")
public void fuck(JoinPoint joinPoint){
System.out.println("do something....%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
}

}
...全文
612 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Old-Summer 2015-05-11
  • 打赏
  • 举报
回复
引用 1 楼 lixu_liuheizi 的回复:
execution(* com.gmc.service*.*(..)) ==> execution(* com.gmc.service.*.*(..)) 试试?
太感谢了!!!
老陈酿 2015-05-11
  • 打赏
  • 举报
回复
execution(* com.gmc.service*.*(..)) ==> execution(* com.gmc.service.*.*(..)) 试试?

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧