我是一个凡人 2016-03-03 06:47 采纳率: 0%
浏览 1671

Spring如何配置多个类

是这样的,我有个工程,有很多的类,我需要对每一个类的每一个方法进行织入,所以需要在xml中进行配置,请问有没有办法不用在xml中编写每一个bean呢,比如类似通过pattern

我从下面的网址下载了一个代码片段

http://www.mkyong.com/spring3/spring-aop-aspectj-in-xml-configuration-example/

其中的例子是这样的:

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd ">


aop:config

expression="execution(* com.mkyong.customer.bo.CustomerBo.addCustomer(..))" />

expression="execution(* com.mkyong.customer.bo.CustomerBo.addCustomer(..))" />

expression="execution(* com.mkyong.customer.bo.CustomerBo.addCustomerReturnValue(..))" />
pointcut-ref="pointCutAfterReturning" />

expression="execution(* com.mkyong.customer.bo.CustomerBo.addCustomerThrowException(..))" />
pointcut-ref="pointCutAfterThrowing" />

expression="execution(* com.mkyong.customer.bo.CustomerBo.addCustomerAround(..))" />

/aop:aspect

/aop:config

如上面的代码片段:

customerBo这个bean是在这里配置的,那如果我有几十个bean的话(不想用interface,因为还需要定义),就需要写几十个配置,有没有办法通过包名,或者类似pattern的方式实现呢

  • 写回答

2条回答 默认 最新

  • Royal_lr 2016-03-03 09:05
    关注

    那你用注解不就好了吗,,每个bean上加个注解,spring中配一个包名就行了

    评论

报告相同问题?

悬赏问题

  • ¥20 怎么在stm32门禁成品上增加记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B
  • ¥15 想问一下stata17中这段代码哪里有问题呀
  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 解riccati方程组