- /**
- * 第四种方式
- * 该类用于替代Spring框架的主配置文件
- * @Configuration:该注解用于替代xml文件中的文件头
- */
- @Configuration
- @ComponentScan("com.spring.entity")
- public class SpringUtil {
-
- //间接获得Student对象
- @Bean(value = "b")
- public Student getStudent(){
- return new Student();
- }
-
- @Bean(value = "d")
- @Scope(value = "prototype")
- public Date getDate(){
- return new Date();
- }
- }
- package com.spring.entity;
-
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.context.annotation.Scope;
- import org.springframework.stereotype.Component;
-
- import javax.annotation.PostConstruct;
- import javax.annotation.PreDestroy;
-
- /**
- * @author MZFAITHDREAM
- * 1 @Scope(v