@Configuration+@Bean & @Component & @Resource/@autowired/@Inject
来源:互联网 发布:bestie软件下载 编辑:程序博客网 时间:2024/04/30 02:39
@Configuration+@Bean
示例代码:
@Configuration@ComponentScan(basePackages = WebConfig.PACKAGE_NAMESPACE)@EnableWebMvcpublic class WebConfig extends WebMvcConfigurerAdapter implements ApplicationContextAware {private ApplicationContext applicationContext;
<span style="white-space:pre"></span>....................
@Beanpublic CommonsMultipartResolver multipartResolver() {final CommonsMultipartResolver commonsMultipartResolver = new CommonsMultipartResolver();commonsMultipartResolver.setMaxUploadSize(MAX_UPLOAD_SIZE);return commonsMultipartResolver;}@Beanpublic TemplateEngine templateEngine() {final SpringTemplateEngine engine = new SpringTemplateEngine();engine.setEnableSpringELCompiler(true);engine.setTemplateResolver(this.templateResolver());return engine;}@Bean(name = "messageSource")public ReloadableResourceBundleMessageSource getMessageSource() {final ReloadableResourceBundleMessageSource resource = new ReloadableResourceBundleMessageSource();resource.setBasenames("classpath:i18n/application-messages");resource.setDefaultEncoding("UTF-8");return resource;}
<span style="white-space:pre"></span>................................
}@Configuration相当于<beans>标签,所以此处WebConfig.class相当于一个xml配置文件而不是一个bean
@Bean相当于<bean>标签,但我的理解是,它所描述的bean只能是没有引入其他类的简单的bean
@Component
示例代码:
@Service@Transactionalpublic class XXServiceImpl implements XXService{@AutowiredTerminalRepository terminalRepository;@AutowiredProductRepository productRepository;...........
@Component(@Controller @Service @Repository) 也相当于<bean>标签,但我的理解是,他们所描述的不是像@Bean那样简单的bean
@Resource/@autowired/@Inject
前面的都是注入的注解,相当于“存”,而这三个就相当于“取”
0 0
- @Configuration+@Bean & @Component & @Resource/@autowired/@Inject
- @Autowired,@Inject,@Resource
- @Autowired @Resource @Inject的区别
- @Resource,@Autowired 和 @Inject的区别
- Spring Injection with @Resource, @Autowired and @Inject
- Spring Injection with @Resource, @Autowired and @Inject
- @Inject和@Autowired以及@Resource区别
- SPRING INJECTION WITH @RESOURCE, @AUTOWIRED AND @INJECT
- Spring依赖注入之@Inject,@Autowired,@Resource
- Spring @Autowired@Component@ Resource注解
- annotation基本配置(@resource,@autowired,@Component...)
- Spring @Resource @Autowired @Component常用注解
- 常用注解分析@RequestMapping @AutoWired@Resource @component
- spring用注解实现注入的@resource,@autowired,@inject区别
- Spring下@Resource, @Autowired和@Inject的区别与联系
- Spring下应用@Resource和@Autowired和@Inject注解
- 装配Bean:JavaConfig@Component@ComponentScan@Configuration
- spring的注解(1): @Configuration,@Bean,@Component,
- gearman rabbitMQ等 异步队列方案
- java中HashSet详解
- 如何解决Win10 Win7 无法通过\\访问winxp文件
- Android UI线程和非UI线程
- 多线程Java
- @Configuration+@Bean & @Component & @Resource/@autowired/@Inject
- JAVA中int、String的类型转换
- 文本分词中词语词性标注说明
- test1
- Toolbar的适配方案
- unity3d中上下左右键控制移动
- Java-IO之Apache Commons IO(1)
- cesiumjs开发实践 (七)
- 今天参与了组织上的第一次会议~