提交 dc632f8f 编写于 作者: Q qinyingjie

fix:FactoryBean使用

上级 dd9b82c6
package com.kwan.spring5.config;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
/**
* 作为配置类,替代 xml 配置文件
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2022/11/14 23:10
*/
@Configuration
@ComponentScan(basePackages = {"com.kwan"})
public class SpringConfig {
}
......@@ -3,7 +3,7 @@ import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* Qualifier注解
* Qualifier注解 需要和Autowired一起使用
*
* @author : qinyingjie
* @version : 2.2.0
......
......@@ -3,7 +3,7 @@ import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* Qualifier注解
* Resource注解 可以用name可以用type
*
* @author : qinyingjie
* @version : 2.2.0
......
import com.kwan.spring5.config.SpringConfig;
import com.kwan.spring5.service.UserService;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
/**
* 完全注解开发
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2022/11/12 18:43
*/
public class Spring_21_ConfigTest {
@Test
public void test1() {
//加载配置类
ApplicationContext context
= new AnnotationConfigApplicationContext(SpringConfig.class);
UserService userService = context.getBean("userService",
UserService.class);
System.out.println(userService);
userService.add();
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册