spring 基础知识

一:降低java开发的复杂性,spring采取了4中关键策略

     1:基于pojo的轻量级和最小侵入性编程;

     2:基于依赖注入和面向接口实现松耦合;

     3:基于切面和惯例进行声明式编程;

     4:通过切面和模板减少样板式代码;

二:javaBeen的三种种定义方式

     1:xml配置

      <bean id="" class = "">(id是javabeen注入的是参考值,class是类文件的路径)

          <constructor-arg ref = ""/>(ref可以使已经定义过的been id 或者是系统变量)

       </bean>

         获取javabeen:

        import springframework.context.support.ClasspathXmlApplicationContext;

        public class KnightMain{

            public static void main(String[] args){

                   ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("xml文件路径");

                   Test test = context.getBeen(Test.class);

                    context.close();

              }

        }

     2:基于java的配置

       package com.test

       import org.springframework.context.annotation.Bean;

        import org.springframework.context.annotation.Configuration;

        import   "定义的javabeen类路径"

         @Configuration

        public class KinghtConfig{

            @Been

            public Test test(){

                return new Test();

             }

        }

3:基于注释

   @Component 组件扫描默认是不开启的,我们需要显示配置一下spring,从而命令他去寻找@Component注解的类,并为其创建bean。开启方式有:在类文件中用@ComponentScan 或者在xml中配置<context:component-scan base-package=""/>

三:切面的xml配置

 

<bean id="aopTest" class = "">(id是javabeen注入的是参考值,class是类文件的路径)

          <constructor-arg ref = ""/>(ref可以使已经定义过的been id 或者是系统变量)

  </bean>

   <aop:config>

            <aop:aspect ref = "aopTest">

                    <aop:pointcut id = "embark" expression = "" />

                    <aop:before pointcut-ref = "embark" method = ""/>

                    <aop:after pointcut-ref = "embark" method = ""/>

            </aop:aspect>

   </aop:config>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值