为了账号安全,请及时绑定邮箱和手机立即绑定
慕课网数字资源数据库体验端
Spring入门篇_学习笔记_慕课网
为了账号安全,请及时绑定邮箱和手机立即绑定

Spring入门篇

moocer JAVA开发工程师
难度中级
时长 7小时 0分
  • 使用Bean注解 在xml中配置了使用注解的方式加载类 定义@Configuration注解的类 在类中实现 @Configuration public class StoreConfig { @Bean("store") public Store getStore(){ return new StringStore(); } } 则context会自动识别到configuration,并识别bean的注解,相当于在xml中配置<bean> 之后可以直接用过context.getBean()获取这个bean
    查看全部
  • @Qualifier注解 1.当ApplicationContext中某一类型的bean有多个时,可以通过该注解减小使用范围,或者直接指定用某一个特定的bean。 eg:@Qualifier("id")//其中id是bean的id 2.@Qualifier注解可以用在成员变量上和成员方法的参数上 3.当使用名称进行bean装配使用时,可以用@Resource注解 注解小结: 1.@Autowired 注解通过类型进行装配 当使用的bean具体到某一名字时,ApplicationContext中又存在多个该类型的bean时,可以结合@Qualifier注解使用,具体到该bean 2.@Resource注解可以将ApplicationContext中多个同一类型的bean具体到某一名字的bean
    查看全部
  • Introductions为匹配到的一个类指定一个父类 types-matching是需要匹配的类 implement-interface是父类的接口 default-impl是父类的实现 <aop:declare-parents types-matching="com.aspect.*(+)" implement-interface="com.aspect.Fit" default-impl="com.aspect.FitImpl" /> 这样子之后就可以在getBean到匹配的类之后,为它包裹一个父类,所以可以强制转换为这个父类 Fit fit = (Fit)super.getBean("aspectBiz");
    查看全部
    0 采集 收起 来源:Introductions应用

    2018-03-22

  • 带参数的方法实现around,在配置中使用直接配置切入点,需要配置对应方法的参数类型,和形参的名称 <aop:around method="around" pointcut="execution(* com.aspect.AspectBiz.init(String, int)) and args(name, time)" /> </aop:aspect> 在around方法中,可以通过这两个参数,对其进行操作 public Object around(ProceedingJoinPoint pjp, String name, int time) throws Throwable { System.out.println(name + " " + time); System.out.println("Around start..."); Object obj = pjp.proceed(); System.out.println("Around stop..."); return obj; }
    查看全部
  • around表示在一个方法执行前或者后执行 <aop:around method="around" pointcut-ref="pointcut"/> 需要在around中加上ProceedingJoinPoint的参数,proceed是执行业务方法,表示在这个方法前后执行输入输出 public Object around(ProceedingJoinPoint pjp) throws Throwable { System.out.println("Around start..."); Object obj = pjp.proceed(); System.out.println("Around stop..."); return obj; }
    查看全部
  • before表示在方法执行前 after表示在方法执行后 after-returning表示在方法正常结束后 after-throwing表示在方法抛出异常后 <aop:config> <aop:aspect id="aspectAOP" ref="aspect"> <aop:pointcut expression="execution(* com.aspect.AspectBiz.*(..))" id="pointcut"/> <aop:before method="before" pointcut-ref="pointcut"/> <aop:after-returning method="afterReturning" pointcut-ref="pointcut"/> <aop:after-throwing method="afterthrowing" pointcut-ref="pointcut"/> <aop:after method="after" pointcut-ref="pointcut"/> </aop:aspect> </aop:config>
    查看全部
  • spring资源
    查看全部
  • 切入点的配置pointcut <aop:config> <aop:aspect id="aspectAOP" ref="aspect"> <aop:pointcut expression="execution(* com.aspect.AspectBiz.*(..))" id="pointcut"></aop:pointcut> </aop:aspect> </aop:config>
    查看全部
  • 声明aspect <bean id="aspect" class="com.aspect.Aspect"></bean> <bean id="aspectBiz" class="com.aspect.AspectBiz"></bean> <aop:config> <aop:aspect id="aspectAOP" ref="aspect"> </aop:aspect> </aop:config>
    查看全部
    0 采集 收起 来源:配置切面aspect

    2018-03-22

  • @Autowired注解: 1.@Autowired注解可以用到spring特殊的接口上: eg: @Autowired ApplicationContext ac; 2.@Autowired可以用到数组注解上,数组的字段或者方法需要的特定类型的bean,将ApplicationContext中该类型的所有bean配装到改数组上。(数组-set,map) map的键存储bean的id,值存储bean。key是String。 @Autowired注解用在数组类型上时,将ApplicationContext里面注册的所有该类型的bean装配到数组上。当希望装配有序时,可以利用@Order注解进行注解 eg: @Order(value=1)(该数值是整型) @Autowired 注意:@Order注解只对数组有序有效。例如map无效
    查看全部
  • 注解说明 @Required 注解适用于bean属性的setter方法,这个注解仅仅表示,受影响的bean属性必须在配置时被填充,通过在bean定义或者通过自动装配一个明确的属性值 @Autowired 可以将用于注解为setter方法,也可用于构造器或成员变量。 默认情况下,如果因找不到合适的bean将会导致autowiring失败抛出异常,可以通过下面方式避免 @Autowired(required=false)
    查看全部
  • Advice的类型
    查看全部
  • AOP相关概念
    查看全部
  • 什么是AOP
    查看全部
  • 注解annotation:类的自动检测和bean注册 1.在类上加上@Componnet,@Service,@Controller@Repository等注解,Spring将会自动检测这些类并将相应的bean注册到Ioc容器中。 2.<context: annotation-config/>在Spring xxx.xml配置文件中使用context标签时需要在头文件中加入相应的xmlns和schemaLocation。该注解只会查找在同一个applicationcontext中的bean注解。 3.为了Spring能够自动检测到注解类并注册相应的bean,需要在xxx.xml配置文件中加入注解:<context:component-scan base-package""/>,base-package是它的属性,意为基于该层次的包进行组件扫描。<context:component-scan>包含了<context:annotation-config> 4.<context:component-scan>和<context:annotation-config>区别: 前者是基于类注解的扫描,会扫描类并将相应的bean注册到applicationContext中,它包含了成员方法和成员变量上的注解,(即包含了后者的功能)。 后者是基于成员方法和成员变量的扫描,使用时bean需要已经在Ioc容器中注册过了。 5.定义bean spring扫描时注解组件被自动检测,相应的bean名称由BeanNameGenerator生成(@Component,@Service,@Controller,@Repository都有一个name属性用于显式的设置bean name)
    查看全部

举报

0/150
提交
取消
课程须知
Java的高级课程,适合对Java基础知识应用自如,并熟悉MVC架构的小伙伴们。如果想成为一名Java工程师,这门课程是一定要学哒。
老师告诉你能学到什么?
掌握依赖注入、IOC和AOP的概念,并能进行简单应用。
友情提示:

您好,此课程属于迁移课程,您已购买该课程,无需重复购买,感谢您对慕课网的支持!