spring笔记

context.component-scan节点
base-package属性告诉spring要扫描的包
use-default-filters=”false”表示不要使用默认的过滤器,此处的默认过滤器,会扫描包含Service,Component,Responsitory,Controller注释修饰类。


@Service告诉spring容器,这是一个Service类,标识持久层Bean组件,默认情况会自动加载它到spring容器中。
@Autowried注解告诉spring,这个字段需要自动注入
@Scope指定此spring bean的scope是单例
@Repository注解指定此类是一个容器类,是DA层类的实现。标识持久层Bean组件
@Componet:基本注解,标识一个受Spring管理的Bean组件
@Controller:标识表现层Bean组件


Filter         Type            Examples Expression    Description
annotation    org.example.SomeAnnotation    符合SomeAnnoation的target class
assignable    org.example.SomeClass    指定class或interface的全名
aspectj    org.example..*Service+    AspetJ语法
regex    org.example.Default.*    Regelar Expression
custom    org.example.MyTypeFilter    Spring3新增自订Type,称作org.springframework.core.type.TypeFilter

 


<?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"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    <context:component-scan base-package="com.sparta.trans" use-default-filters="false">  

              <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>      

        </context:component-scan>

 </beans>
 
 
 
 <?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"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
          http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    
    <context:component-scan base-package="com.point.plat.protocol" />
</beans>

 

<context:component-scan base-package="com.test.scan.core" >
    <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
    <!--含义是这里我们不扫描core包下所有的@Repository注解-->
    <!--当然也可以设置为@Service、@Controller、@Component、@Configuration其中一种-->
</context:component-scan>


<context:component-scan base-package="com.test.scan.core" >
    <context:exclude-filter type="assignable" expression="com.test.scan.core.UserImpl"/>
    <!--含义是这里我们不扫描指定UserImpl类-->
</context:component-scan>

 

<context:component-scan base-package="com.test.scan.core" >
    <context:exclude-filter type="aspectj" expression="com.test.scan..*"/>
    <!--通过aop的方式-->
</context:component-scan>


<context:component-scan base-package="com.test.scan.core" >
    <context:exclude-filter type="regex" expression=".test.scan.*"/>
    <!--通过aop的方式-->
</context:component-scan>

 

@Transactional 事务

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值