记录spring加载方式

context = new ClassPathXmlApplicationContext("beans.xml")

 

而另一种指定文件名的加载方式

 

String path[]={appPath1+"applicationContext.xml",appPath1+"handerContext.xml"};

ctx = new FileSystemXmlApplicationContext(

path

);

 

关于 spring bean 的使用,都在spring 容易中有定义才允许使用spring bean

例如在handerContext.xml 中定义srping bean

最后使用  ctx.getBean(name);去获取这个bean 去操作。

整个系统大部分的关键类都交由spring去托管,如使用了注释 类似@Resource 或者@Service 等都必须在

    <context:component-scan base-package="com">  

         <context:include-filter type="regex" expression="com/.game/.dao/.impl.*"/>  

         <context:exclude-filter type="regex" expression="com/.game/.service.*"/>  

         <context:exclude-filter type="regex" expression="com/.game/.function.*"/>  

         <context:exclude-filter type="regex" expression="com/.game/.service/.impl..*"/>  

    </context:component-scan>  

中有定义才行。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring中,可以使用@Order注解来指定AOP的加载顺序。具体步骤如下: 1. 在需要进行AOP的类上添加@Aspect注解,表示该类是一个切面 2. 在切面类中定义多个切点和通知 3. 在通知方法上添加@Order注解,指定通知的优先级,数字越小优先级越高(默认优先级为0) 4. 在Spring配置文件中使用<aop:aspectj-autoproxy>标签启用自动代理功能 例如,我们有两个切面类,分别是LoggingAspect和TransactionAspect,其中LoggingAspect负责记录日志,TransactionAspect负责管理事务。我们希望先记录日志再管理事务,那么可以按照以下方式指定顺序: ``` @Aspect public class LoggingAspect { @Pointcut("execution(* com.example.service.*.*(..))") public void servicePointcut() {} @Before("servicePointcut()") @Order(1) public void beforeService() { System.out.println("记录日志开始"); } @AfterReturning("servicePointcut()") @Order(1) public void afterService() { System.out.println("记录日志结束"); } } @Aspect public class TransactionAspect { @Pointcut("execution(* com.example.service.*.*(..))") public void servicePointcut() {} @Before("servicePointcut()") @Order(2) public void beforeService() { System.out.println("开启事务"); } @After("servicePointcut()") @Order(2) public void afterService() { System.out.println("提交事务"); } } ``` 在这个例子中,我们在LoggingAspect和TransactionAspect的通知方法上分别添加了@Order注解,指定了它们的执行顺序。在Spring配置文件中,我们启用了自动代理功能,让Spring自动将切面类转换为代理对象,并在调用服务方法时自动触发切面的通知方法,从而实现AOP功能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值