import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class AppConfig {
@Bean
public MyService myService() {
return new MyServiceImpl();
}
}
// 解释说明:
// 在Spring框架中,@Bean注解用于在配置类中定义一个方法,该方法返回一个对象,这个对象将被注册为Spring容器中的一个bean。
// 上面的代码中,AppConfig是一个配置类,使用了@Configuration注解。myService方法上使用了@Bean注解,表示该方法返回的对象(MyServiceImpl实例)将被注册为Spring容器中的一个bean,名称为myService。
上一篇:java全局变量定义
下一篇:java的多态
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站