(spring-第4回【IoC基础篇】)spring基于注解的配置

基于XML的bean属性配置:bean的定义信息与bean的实现类是分离的。

基于注解的配置:bean的定义信息是通过在bean实现类上标注注解实现。

也就是说,加了注解,相当于在XML中配置了,一样一样的。

一、举个栗子:

 1 package com.mesopotamia.annotation;
 2
 3 import org.springframework.stereotype.Component;
 4
 5 @Component
 6 public class Car {
 7     private String name;
 8     private String color;
 9     private double price;
10     public Car(){
11         name="保时捷";
12         color="黄色";
13     }
14     public String getName() {
15         return name;
16     }
17     public void setName(String name) {
18         this.name = name;
19     }
20     public String getColor() {
21         return color;
22     }
23     public void setColor(String color) {
24         this.color = color;
25     }
26     public double getPrice() {
27         return price;
28     }
29     public void setPrice(double price) {
30         this.price = price;
31     }
32
33     public String toString(){
34         return "名字:"+name+" 颜色:"+color+" 价格:"+price;
35     }
36 }

第5行标注Component:spring看到这个属性标志,会自动将Car变成容器管理类,等同于在XML中这样配置:

1 <bean id="car" class="com.mesopotamia.annotation.Car"></bean>

二、spring启动之前的配置?

 1 <?xml version="1.0" encoding="UTF-8" ?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4     xmlns:context="http://www.springframework.org/schema/context"
 5     xsi:schemaLocation="http://www.springframework.org/schema/beans
 6          http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
 7          http://www.springframework.org/schema/context
 8          http://www.springframework.org/schema/context/spring-context-3.0.xsd"
 9          >
10    <context:component-scan base-package="com.mesopotamia.annotation"/>
11 </beans>

如上,

使用空间:context,

使用context的规则:component-scan.

第10行的意义:扫描这个包中的所有类,并从注解信息中获取bean的基本信息(没加注解的不扫描也不实例化)。

三、如何启动?

按正常方式启动即可加载(自己复习spring容器的加载),例如:

 1 package com.mesopotamia.annotation;
 2
 3 import org.springframework.context.ApplicationContext;
 4 import org.springframework.context.support.ClassPathXmlApplicationContext;
 5
 6 public class Main {
 7
 8     public static void main(String args[]){
 9         ApplicationContext ctx = new ClassPathXmlApplicationContext("com/mesopotamia/annotation/beans.xml");
10         Car car= ctx.getBean(Car.class);
11         System.out.println(car.toString());
12     }
13
14 }

第10行就已经实例化Car了,并且实例化之前先跑了Car的构造函数给car的属性附了值(因为我给构造函数里专门写了赋值语句,没写的话,属性是没有赋值的,除非见了鬼)。

下面是打印信息,从下面第4行结果可以看到已经附了值。

1 2015-11-13 23:44:18,414  INFO [main] (AbstractApplicationContext.java:456) - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@e80a59: startup date [Fri Nov 13 23:44:18 CST 2015]; root of context hierarchy
2 2015-11-13 23:44:18,480  INFO [main] (XmlBeanDefinitionReader.java:315) - Loading XML bean definitions from class path resource [com/mesopotamia/annotation/beans.xml]
3 2015-11-13 23:44:18,728  INFO [main] (DefaultListableBeanFactory.java:555) - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@121ab80: defining beans [car,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor]; root of factory hierarchy
4 名字:保时捷 颜色:黄色 价格:0.0

四、context:component-scan的配置直接选了相应包里的全部class,有没有更多的过滤方式?

有。context:component-scan标签下面可以再加子标签,如:

1 <context:component-scan base-package="com.baobaotao">
2        <context:include-filter type="aspectj" expression="com.baobaotao.anno.*Plugin+"/>
3        <context:exclude-filter type="regex" expression="cn\.outofmemory\.spring\.[^.]+(Dao|Service)"/> 4</context:component-scan>

include-filter表示:包含哪些。type是类型,expression是表达式过滤。

exclude-filter表示:除去哪些。type是类型,expression是表达式过滤。

第二行表示:com.baobaotao.anno包下面所有以Plugin结尾的class。

第三行表示:除去所有以Dao或者Service结束的类。具体规则这里先不作讨论,你要觉得你行,那你自己先啃啃里面的肉(先去复习一下正则表达式)

其他过滤表达式举例:

五、除了Component外,其他的注解都有什么?

1、@Component 一般的bean类上面配置。

2、@Controller 对应表现层的Bean,也就是action。

3、@ Service 对应业务层bean。

4、@ Repository 对应持久层Bean。

上面的4种起到相同的效果,都是注入bean,注入bean的四大金刚,张龙赵虎王朝马汉,辅佐包黑炭。

5、@Autowired 成员变量或方法入参处标注,按类型匹配自动注入。

6、@Qualifier 按名称匹配方式注入。

7、@PostConstruct指定初始化方法。(相当于XML配置中的init-method)

8、@PreDestroy指定销毁方法。(相当于XML配置中的destroy-method)

9、@Scope 指定bean是prototype还是singleton。

六、上面这几个注解给个具体例子说明下?

不想往下看的可以去陪女朋友了,因为重点已经讲完了。下面是一个简单登录界面的栗子,为了突出重点,关于spring web方面的机制暂时不讲,只讲有关注解的部分,如果你还没看过spring web应用部分也无妨,下面的例子只涉及注解注入部分:

XML配置文件如下:

 1 <?xml version="1.0" encoding="UTF-8" ?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4     xmlns:p="http://www.springframework.org/schema/p"
 5     xmlns:context="http://www.springframework.org/schema/context"
 6     xmlns:aop="http://www.springframework.org/schema/aop"
 7     xmlns:tx="http://www.springframework.org/schema/tx"
 8     xsi:schemaLocation="http://www.springframework.org/schema/beans
 9        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
10        http://www.springframework.org/schema/context
11        http://www.springframework.org/schema/context/spring-context-3.0.xsd
12        http://www.springframework.org/schema/tx
13        http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
14        http://www.springframework.org/schema/aop
15        http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
16
17     <!-- 扫描类包,将标注Spring注解的类自动转化Bean,同时完成Bean的注入 -->
18     <context:component-scan base-package="com.baobaotao.dao"/>
19     <context:component-scan base-package="com.baobaotao.service"/>
20     <context:component-scan base-package="com.baobaotao.domain"/>
21
22     <!-- 配置数据源 -->
23     <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
24         destroy-method="close"
25         p:driverClassName="com.mysql.jdbc.Driver"
26         p:url="jdbc:mysql://localhost:3306/sampledb"
27         p:username="root"
28         p:password="2009118293zjl" />
29
30     <!-- 配置Jdbc模板  -->
31     <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"
32         p:dataSource-ref="dataSource" />
33
34     <!-- 配置事务管理器 -->
35     <bean id="transactionManager"
36         class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
37         p:dataSource-ref="dataSource" />
38
39     <!-- 通过AOP配置提供事务增强,让service包下所有Bean的所有方法拥有事务 -->
40     <aop:config proxy-target-class="true">
41         <aop:pointcut id="serviceMethod"
42             expression=" execution(* com.baobaotao.service..*(..))" />
43         <aop:advisor pointcut-ref="serviceMethod" advice-ref="txAdvice" />
44     </aop:config>
45     <tx:advice id="txAdvice" transaction-manager="transactionManager">
46         <tx:attributes>
47             <tx:method name="*" />
48         </tx:attributes>
49     </tx:advice>
50 </beans>

重点第18到20行:spring只扫描配置路径下所有带注解的地方来注入相关数据。其他行先不看,你想看我也不拦你。

WEB应用后台java分三层:control、service、dao层,简单讲一下,直接与jsp交互的就是control层,直接操作数据库的是dao层(持久层,数据库里的数据都是持久性的嘛),service层负责把dao层数据拿到,经过处理,返回给control层。control层拿到数据再交给jsp前台。(dao就是程序员,service就是老板,control就是客户,程序员做东西,客户使用,而老板是桥梁)

下面是control层:

 1 package com.baobaotao.web;
 2
 3 import java.util.Date;
 4
 5 import javax.annotation.PostConstruct;
 6 import javax.annotation.PreDestroy;
 7 import javax.servlet.http.HttpServletRequest;
 8
 9
10 import org.apache.commons.logging.Log;
11 import org.apache.commons.logging.LogFactory;
12 import org.springframework.beans.factory.annotation.Autowired;
13 import org.springframework.stereotype.Controller;
14 import org.springframework.web.bind.annotation.RequestMapping;
15 import org.springframework.web.servlet.ModelAndView;
16
17 import com.baobaotao.domain.User;
18 import com.baobaotao.service.UserService;
19
20 @Controller
21 public class LoginController{
22     Log log=LogFactory.getLog(LoginController.class);
23
24     @Autowired(required=false)
25     private UserService userService;
26
27     @RequestMapping(value = "/loginCheck.do")
28     public ModelAndView loginCheck(HttpServletRequest request,LoginCommand loginCommand){
29         boolean isValidUser = userService.hasMatchUser(loginCommand.getUserName(),loginCommand.getPassword());
30         if (!isValidUser) {
31             return new ModelAndView("login", "error", "用户名或密码错误。");
32         } else {
33             User user = userService.findUserByUserName(loginCommand
34                     .getUserName());
35             user.setLastIp(request.getLocalAddr());
36             user.setLastVisit(new Date());
37             userService.loginSuccess(user);
38             request.getSession().setAttribute("user", user);
39
40             return new ModelAndView("main");
41         }
42     }
43
44     @PostConstruct
45     public void init(){
46         log.info("本应用程序正式拉开帷幕。。。");
47     }
48
49     @PreDestroy
50     public void destroy(){
51         log.info("本应用程序正式落幕,吓吓侬。。。");
52     }
53 }

这里用到了几个注解,

spring看到@Controller会如同看到@Component一样,转换成spring容器管理的bean。

spring看到@Autowired(required=false)会自动注入(实例化)下面的userService。(直接用就行,就不用你来new一个对象啦)。

spring看到@PostConstruct就会在实例化本Bean后接着执行这个方法;

spring看到@PreDestroy就会在销毁之前执行下面的方法;

你的眼神告诉我你不相信我。好的,咱们看日志:

tomcat启动的时候spring容器会自动加载,下面是tomcat启动的日志:

1 。。。。。。
 2
 3 2015-11-15 21:24:31,673 DEBUG [main] (DefaultSingletonBeanRegistry.java:214) - Creating shared instance of singleton bean 'userDao'
 4 2015-11-15 21:24:31,674 DEBUG [main] (AbstractAutowireCapableBeanFactory.java:430) - Creating instance of bean 'userDao'
 5 2015-11-15 21:24:31,674 DEBUG [main] (AbstractBeanFactory.java:242) - Returning cached instance of singleton bean 'org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0'
 6
 7 。。。。。。
 8
 9 2015-11-15 21:24:31,676 DEBUG [main] (InjectionMetadata.java:82) - Processing injected method of bean 'userDao': AutowiredFieldElement for private org.springframework.jdbc.core.JdbcTemplate com.baobaotao.dao.UserDao.jdbcTemplate
10 2015-11-15 21:24:31,677 DEBUG [main] (AbstractBeanFactory.java:242) - Returning cached instance of singleton bean 'jdbcTemplate'
11 2015-11-15 21:24:31,677 DEBUG [main] (AutowiredAnnotationBeanPostProcessor.java:420) - Autowiring by type from bean name 'userDao' to bean named 'jdbcTemplate'
12
13 。。。。。。
14
15 2015-11-15 21:24:31,678 DEBUG [main] (AbstractAutowireCapableBeanFactory.java:458) - Finished creating instance of bean 'userDao'
16
17
18 。。。。。。
19
20 2015-11-15 21:24:31,679 DEBUG [main] (DefaultSingletonBeanRegistry.java:214) - Creating shared instance of singleton bean 'userService'
21 2015-11-15 21:24:31,679 DEBUG [main] (AbstractAutowireCapableBeanFactory.java:430) - Creating instance of bean 'userService'
22 2015-11-15 21:24:31,679 DEBUG [main] (AbstractBeanFactory.java:242) - Returning cached instance of singleton bean 'org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0'
23 2015-11-15 21:24:31,680  INFO [main] (UserService.java:18) - 实例化了UserService...
24
25 。。。。。。
26
27 2015-11-15 21:24:31,683 DEBUG [main] (InjectionMetadata.java:82) - Processing injected method of bean 'userService': AutowiredFieldElement for private com.baobaotao.dao.UserDao com.baobaotao.service.UserService.userDao
28 2015-11-15 21:24:31,685 DEBUG [main] (AbstractBeanFactory.java:242) - Returning cached instance of singleton bean 'userDao'
29 2015-11-15 21:24:31,685 DEBUG [main] (AutowiredAnnotationBeanPostProcessor.java:420) - Autowiring by type from bean name 'userService' to bean named 'userDao'
30 2015-11-15 21:24:31,686 DEBUG [main] (InjectionMetadata.java:82) - Processing injected method of bean 'userService': AutowiredFieldElement for private com.baobaotao.dao.LoginLogDao com.baobaotao.service.UserService.loginLogDao
31 2015-11-15 21:24:31,686 DEBUG [main] (AbstractBeanFactory.java:242) - Returning cached instance of singleton bean 'loginLogDao'
32 2015-11-15 21:24:31,687 DEBUG [main] (AutowiredAnnotationBeanPostProcessor.java:420) - Autowiring by type from bean name 'userService' to bean named 'loginLogDao'
33
34 。。。。。。
35
36 2015-11-15 21:24:32,093  INFO [main] (UserService.java:18) - 实例化了UserService...
37 2015-11-15 21:24:32,094 DEBUG [main] (AbstractAutowireCapableBeanFactory.java:458) - Finished creating instance of bean 'userService'
38 2015-11-15 21:24:32,094 DEBUG [main] (DefaultSingletonBeanRegistry.java:214) - Creating shared instance of singleton bean 'loginLog'
39
40 。。。。。。
41
42 015-11-15 21:24:32,252  INFO [main] (DefaultListableBeanFactory.java:555) - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@c272bc: defining beans [loginController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.web.servlet.view.InternalResourceViewResolver#0]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory@691dee
43 2015-11-15 21:24:32,252 DEBUG [main] (DefaultSingletonBeanRegistry.java:214) - Creating shared instance of singleton bean 'loginController'
44 2015-11-15 21:24:32,254 DEBUG [main] (AbstractAutowireCapableBeanFactory.java:430) - Creating instance of bean 'loginController'
45 2015-11-15 21:24:32,255  INFO [main] (LoginController.java:25) - 实例化了LoginController...
46 2015-11-15 21:24:32,264 DEBUG [main] (InitDestroyAnnotationBeanPostProcessor.java:200) - Found init method on class [com.baobaotao.web.LoginController]: public void com.baobaotao.web.LoginController.init()
47 2015-11-15 21:24:32,265 DEBUG [main] (InitDestroyAnnotationBeanPostProcessor.java:208) - Found destroy method on class [com.baobaotao.web.LoginController]: public void com.baobaotao.web.LoginController.destroy()
48 2015-11-15 21:24:32,265 DEBUG [main] (InitDestroyAnnotationBeanPostProcessor.java:251) - Found init method on class [com.baobaotao.web.LoginController]: org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement@316510
49 2015-11-15 21:24:32,265 DEBUG [main] (InitDestroyAnnotationBeanPostProcessor.java:259) - Found destroy method on class [com.baobaotao.web.LoginController]: org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement@5cd39ffa
50 2015-11-15 21:24:32,266 DEBUG [main] (InjectionMetadata.java:59) - Found injected element on class [com.baobaotao.web.LoginController]: AutowiredFieldElement for private com.baobaotao.service.UserService com.baobaotao.web.LoginController.userService
51 2015-11-15 21:24:32,267 DEBUG [main] (AbstractAutowireCapableBeanFactory.java:504) - Eagerly caching bean 'loginController' to allow for resolving potential circular references
52 2015-11-15 21:24:32,268 DEBUG [main] (InjectionMetadata.java:82) - Processing injected method of bean 'loginController': AutowiredFieldElement for private com.baobaotao.service.UserService com.baobaotao.web.LoginController.userService
53 2015-11-15 21:24:32,269 DEBUG [main] (AbstractBeanFactory.java:242) - Returning cached instance of singleton bean 'userService'
54 2015-11-15 21:24:32,270 DEBUG [main] (AutowiredAnnotationBeanPostProcessor.java:420) - Autowiring by type from bean name 'loginController' to bean named 'userService'
55 2015-11-15 21:24:32,271 DEBUG [main] (InitDestroyAnnotationBeanPostProcessor.java:291) - Invoking init method on bean 'loginController': public void com.baobaotao.web.LoginController.init()
56 2015-11-15 21:24:32,271  INFO [main] (LoginController.java:50) - 本应用程序正式拉开帷幕。。。
57 2015-11-15 21:24:32,271 DEBUG [main] (AbstractAutowireCapableBeanFactory.java:458) - Finished creating instance of bean 'loginController'
58
59 。。。。。。

第44、45行是实例化LoginController,

第46/47行是根据@PostContruct和@PreDestroy发现了我们定义的初始化和销毁方法。

第53行,spring直接给了我们一个userService对象(因为它看到了@Autowired,required=false是说如果找不到对应的bean不报异常)。

第56行,spring看到@PostContruct执行了初始化方法。

当我把tomcat停掉,spring容器就会销毁,那么是不是要执行@PreDestroy下面的销毁方法?当然,你要相信科学,看停掉tomcat的日志:

。。。。。
5 2015-11-15 21:53:15,763 DEBUG [main] (InitDestroyAnnotationBeanPostProcessor.java:303) - Invoking destroy method on bean 'loginController': public void com.baobaotao.web.LoginController.destroy()
6 2015-11-15 21:53:15,763  INFO [main] (LoginController.java:55) - 本应用程序正式落幕,吓吓侬。。。
7 2015-11-15 21:53:15 org.apache.catalina.core.ApplicationContext log
8 信息: Closing Spring root WebApplicationContext
9 2015-11-15 21:53:15,764  INFO [main] (AbstractApplicationContext.java:1002) - Closing Root WebApplicationContext: startup date [Sun Nov 15 21:24:29 CST 2015]; root of context hierarchy

第六行果然执行了销毁方法。

请解释前面那个日志里第53行的Returning cached instance of singleton bean 'userService'。

是这样的,先看UserService的部分代码:

1 @Service
2 public class UserService {
3     private static Log log=LogFactory.getLog(UserService.class);
4     public UserService(){
5         log.info("实例化了UserService...");
6     }

我在这个类中注释了@Service,spring在启动的时候跟@Component、@Controller、@Repository一样,会自动把bean信息注入容器中(即把bean在spring容器中实例化),也就是说,当spring看到@Service时,会自动返回一个提前实例化好的UserService,而只要UserService上面不显式标注:@Scope("prototype"),那么默认UserService就是单例模式的。单例模式下,spring会把bean放到IoC容器的缓存池中,而把bean的引用返回给调用者。这就是Returning cached instance of singleton bean 'userService'这句话的意义。

好的,我把UserService的注解改成下面的方式:

1 @Service
2 @Scope("prototype")
3 public class UserService {
4     private static Log log=LogFactory.getLog(UserService.class);
5     public UserService(){
6         log.info("实例化了UserService...");
7     }
8     

那么启动tomcat打印日志如下:

 1 2015-11-15 22:11:09,723 DEBUG [main] (Cglib2AopProxy.java:755) - Method is declared on Advised interface: public abstract int org.springframework.aop.framework.Advised.indexOf(org.aopalliance.aop.Advice)
 2 2015-11-15 22:11:09,724 DEBUG [main] (Cglib2AopProxy.java:755) - Method is declared on Advised interface: public abstract int org.springframework.aop.framework.Advised.indexOf(org.springframework.aop.Advisor)
 3 2015-11-15 22:11:09,724 DEBUG [main] (Cglib2AopProxy.java:755) - Method is declared on Advised interface: public abstract java.lang.Class org.springframework.aop.TargetClassAware.getTargetClass()
 4 2015-11-15 22:11:09,760  INFO [main] (UserService.java:20) - 实例化了UserService...
 5 2015-11-15 22:11:09,760 DEBUG [main] (AbstractAutowireCapableBeanFactory.java:458) - Finished creating instance of bean 'userService'
 6 2015-11-15 22:11:09,761 DEBUG [main] (AutowiredAnnotationBeanPostProcessor.java:420) - Autowiring by type from bean name 'loginController' to bean named 'userService'
 7 2015-11-15 22:11:09,761 DEBUG [main] (InitDestroyAnnotationBeanPostProcessor.java:291) - Invoking init method on bean 'loginController': public void com.baobaotao.web.LoginController.init()
 8 2015-11-15 22:11:09,761  INFO [main] (LoginController.java:50) - 本应用程序正式拉开帷幕。。。
 9 2015-11-15 22:11:09,761 DEBUG [main] (AbstractAutowireCapableBeanFactory.java:458) - Finished creating instance of bean 'loginController'
10 2015-11-15 22:11:09,761 DEBUG [main] (AbstractBeanFactory.java:242) - Returning cached instance of singleton bean 'org.springframework.context.annotati

你会看到,在拉开帷幕之前,又实例化了一次UserService,这就是prototype的作用。

再看:

 1 @Controller
 2 public class LoginController{
 3     Log log=LogFactory.getLog(LoginController.class);
 4
 5     public LoginController(){
 6         log.info("实例化了LoginController...");
 7     }
 8
 9     @Autowired(required=false)
10     @Qualifier("service")
11     private UserService userService;
12    

第10行,我在userService上面加了 @Qualifier("service")的注释,这个表示,我引用的是名字为service的bean的实例,那么你要给UserService起个名字叫service:

1 @Service("service")
2 @Scope("prototype")
3 public class UserService {
4     private static Log log=LogFactory.getLog(UserService.class);
5     public UserService(){
6         log.info("实例化了UserService...");
7     }
8     

像第一行那样。(Component、Controller、Repository也是那样命名,如果是基于XML的注入如何命名?自己复习去。)

不加的话,系统找不到对应的bean,就会报错。

spring容器的三座大山:XML配置文件(或者注解配置、bean配置等),spring容器,bean类。不管是基于XML还是基于注解,无非就是为了把bean信息注入到spring容器中,南拳和北腿,各有千秋。下面是二者的对比:

本节内容就讲到这里。

吾生也有涯,而知也无涯。

            ——《庄子》

本文转自于: http://www.cnblogs.com/mesopotamia/p/4963659.html

(spring-第4回【IoC基础篇】)spring基于注解的配置相关推荐

  1. Spring学习(六)-Bean作用域与基于注解的配置

    Bean作用域 在配置文件中定义Bean时,用户不但可以配置Bean的属性值以及相互之间的依赖关系,还可以定义Bean的作用域.作用域将对Bean的生命周期和创建方式产生影响.Spring一般采用sc ...

  2. IoC基础篇(一)--- Spring容器中Bean的生命周期

    IoC基础篇(一)--- Spring容器中Bean的生命周期 日出日落,春去秋来,花随流水,北雁南飞,世间万物皆有生死轮回.从调用XML中的Bean配置信息,到应用到具体实例中,再到销毁,Bean也 ...

  3. Spring IoC — 基于注解的配置

    基于XML的配置,Bean定义信息和Bean实现类本身是分离的,而采用基于注解的配置方式时,Bean定义信息即通过在Bean实现类上标注注解实现. @Component:对类进行标注,Spring容器 ...

  4. spring IOC容器 Bean 管理——基于注解方式

    IOC 操作 Bean 管理(基于注解方式) 1.什么是注解 ​ (1)注解是代码特殊标记,格式:@注解名称(属性名称=属性值, 属性名称=属性值-) ​ (2)使用注解,注解作用在类上面,方法上面, ...

  5. Spring 基于注解的配置

    转载自  Spring 基于注解的配置 基于注解的配置 从 Spring 2.5 开始就可以使用注解来配置依赖注入.而不是采用 XML 来描述一个 bean 连线,你可以使用相关类,方法或字段声明的注 ...

  6. spring基于注解的配置

    转自:https://www.cnblogs.com/mesopotamia/p/4963659.html 基于XML的bean属性配置:bean的定义信息与bean的实现类是分离的. 基于注解的配置 ...

  7. Ansible系列-基础篇-Ansible Inventory的合理化配置

    欢迎关注个人公众号 DailyJobOps 原文地址:Ansible系列-基础篇-Ansible Inventory的合理化配置 这里写目录标题 Ansible Inventory内置参数 Inven ...

  8. Spring学习第6篇: 基于注解使用IOC

    大家家好,我是一名网络怪咖,北漂五年.相信大家和我一样,都有一个大厂梦,作为一名资深Java选手,深知Spring重要性,现在普遍都使用SpringBoot来开发,面试的时候SpringBoot原理也 ...

  9. Spring基础篇——Spring容器和应用上下文理解

    转载自 https://www.cnblogs.com/chenbenbuyi/p/8166304.html 上文说到,有了Spring之后,通过依赖注入的方式,我们的业务代码不用自己管理关联对象的生 ...

最新文章

  1. linux怎么装谷歌浏览器,如何在linux CentOS 上安装chrome 谷歌浏览器?
  2. python快速部署一个服务器_Python加Shell快速部署集群
  3. Python基础概念_6_模块
  4. 二叉树已知先序和中序输出后序
  5. 后台服务系统之Dubbo协议
  6. 在家办公这半年,让我开始热爱生活
  7. cascade sqlite 数据库_ON DELETE CASCADE无法正常工作在ios中的sqlite3中
  8. REVERSE-PRACTICE-BUUCTF-29
  9. notepad快捷键大全
  10. 【BZOJ】1969: [Ahoi2005]LANE 航线规划
  11. 嵌入式Linux--使用libpng库解码png图片
  12. 一款微信小程序商城项目(附源码)
  13. java中时钟回拨,【追光者系列】HikariCP源码分析之evict、时钟回拨、连接创建生命周期...
  14. HTML网页头部小图标
  15. linux c语言俄罗斯方块,C语言俄罗斯方块游戏解析(图文+源码)
  16. 光功率 博科交换机_FAQ-交换机是否支持查看光模块型号及收发光功率
  17. java uuid去掉横线_UUID去横杠-的正确方式
  18. 基于MUI的电影新闻的webapp项目开发
  19. 关于何如在英伟达官网上下载历史驱动的方法
  20. import * as 是什么?

热门文章

  1. 参加首届“全球程序员节”感想
  2. 【Android】 app inventor | 零基础开发移动应用[1]
  3. iPad 在线音乐播放器
  4. 【我的成长之路——英语】——good luck charlie
  5. 国在产vr视频区_九台vr技术安全体验馆VR行走平台资讯
  6. Android实现手势解锁
  7. 图新地球GIS+BIM工程设计施工管理平台
  8. 项目管理----计划------WPS画甘特图做任务排期
  9. tensorflow目标检测API实现
  10. 交换机VSU相关显示命令