spring-210727-07–IOC容器–Bean管理注解方式-完全注解开发
创建配置类,替代xml配置文件
SpringConfig.java
package com.bgy.spring.config;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@ComponentScan(basePackages = {"com.bgy.spring"})
public class SpringConfig {
}
TestUser04.java
import com.bgy.spring.config.SpringConfig;
import com.bgy.spring.service.UserService03;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class TestUser04 {
@Test
public void test(){
ApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class);
UserService03 userService03 = context.getBean("userService03", UserService03.class);
System.out.println(userService03);
userService03.add();
}
}