Spring6-全注解开发

全注解开发就是不再使用spring配置文件了,写一个配置类来代替配置文件。

package com.wsy.config;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
 * @author within
 * @date 2023-02-10 12:03
 */
@Configuration
//@ComponentScan({"com.atguigu.spring6.controller", "com.atguigu.spring6.service","com.atguigu.spring6.dao"})
@ComponentScan("com.wsy")
public class Spring6Config {
}

测试类

    @Test
    public void testAllAnnotation(){
        ApplicationContext context = new AnnotationConfigApplicationContext(Spring6Config.class);
        UserController userController = context.getBean("userController", UserController.class);
        userController.addController();
        logger.info("执行成功");
    }

猜你喜欢

转载自blog.csdn.net/qq_41264674/article/details/128969324