今日收获-context:component-scan
2018-07-20 05:49:42来源:博客园 阅读 ()
一、要有命名空间 xmlns:context="http://www.springframework.org/schema/context"
二、作用:直接上解释吧!
Scans the classpath for annotated components that will be auto-registered as Spring beans. By default,
the Spring-provided @Component, @Repository, @Service, @Controller, @RestController,
@ControllerAdvice, and @Configuration stereotypes will be detected. Note: This tag implies the effects
of the 'annotation-config' tag, activating @Required, @Autowired, @PostConstruct, @PreDestroy,
@Resource, @PersistenceContext and @PersistenceUnit annotations in the component classes, which is
usually desired for autodetected components (without external configuration). Turn off the 'annotation-
config' attribute to deactivate this default behavior, for example in order to use custom
BeanPostProcessor definitions for handling those annotations. Note: You may use placeholders in
package paths, but only resolved against system properties (analogous to resource paths). A
component scan results in new bean definitions being registered; Spring's
PropertySourcesPlaceholderConfigurer will apply to those bean definitions just like to regular bean
definitions, but it won't apply to the component scan settings themselves. See javadoc for
org.springframework.context.annotation.ComponentScan for information on code-based alternatives to
bootstrapping component-scanning.
Content Model : (include-filter*, exclude-filter*)
三、实例
<!-- 配置自动扫描的包 -->
<context:component-scan
base-package="com.it.aop"></context:component-scan>
@Component("arithmeticCalculator")
public class ArithmeticCalculatorImpl
ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");
ArithmeticCalculator arithmeticCalculator = (ArithmeticCalculator) ctx.getBean("arithmeticCalculator");
-- 释放资源
((ConfigurableApplicationContext)ctx).close();
int result = arithmeticCalculator.add(1, 2);System.out.println("result:" + result);
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- JAVA实习面经+面试常问问题和流程(商汤,今日头条,微博) 2020-04-15
- string 面试题,看完这五个你保证会有所收获的 2020-04-13
- redis笔记 2019-10-12
- EL&JSTL笔记 2019-10-08
- Response笔记 2019-10-08
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash