首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

spring配置文件有关问题

2013-09-11 
spring配置文件问题spring的配置文件,applicationContext.xml中有这样一条配置context:component-scan ba

spring配置文件问题
spring的配置文件,applicationContext.xml中有这样一条配置

<context:component-scan base-package="com.strongit.nj" />,这条配置的作用是扫描com.strongit.nj包下的所有类。
我的疑惑是扫描这些类时会做那些事?(本人猜测,会将扫码的类注册到spring容器,即实例化这些类,再者是读取被扫描的类上的spring注解)有哪位大神知道的给小弟指点一二,不胜感激!

[解决办法]
根据注解将对应的类型实例化,注入到目标属性上
[解决办法]
扫描这些包下有注解的,自动注入呗
[解决办法]
可以看文档么, 默认扫描 @Component, @Repository, @Service, and @Controller 注解。



Scans the classpath for annotated components that will be auto-registered as
Spring beans. By default, the Spring-provided @Component, @Repository,
@Service, and @Controller 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 definition
being registered; Spring's PropertyPlaceholderConfigurer 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.


[解决办法]
扫描spring框架定义的注解信息,并解析这些注解信息。

热点排行