1、Spring注解方式bean容器管理
<context:component-scan base-package="com"/><!---通过该语句可以搜索com及com下子包中的类->
<mvc:annotation-driven/>
相当于注册了DefaultAnnotationHandlerMapping和AnnotationMethodHandlerAdapter两个bean,配置一些messageconverter。即解决了@Controller注解的使用前提配置。
或
“<context:annotation-config/>
<context:component-scan base-package="com.yineng" /> ”
说明:
<context:component-scan base-package="com.yineng" /> 配置项不但启用了对类包进行扫描以实施注释驱动 Bean 定义的功能,同时还启用了注释驱动自动注入的功能(即还隐式地在内部注册了 AutowiredAnnotationBeanPostProcessor 和 CommonAnnotationBeanPostProcessor),因此当使用 <context:component-scan/> 后,除非需要使用PersistenceAnnotationBeanPostProcessor和equiredAnnotationBeanPostProcessor两个Processor的功能(例如JPA等)否则就可以将 <context:annotation-config/> 移除了
<context:annotation-config/>
隐式地向Spring容器中注册AutowiredAnnotationBeanPostProcessor、CommonAnnotationBeanPostProcessor、PersistenceAnnotationBeanPostProcessor 及 equiredAnnotationBeanPostProcessor 这 4 个 BeanPostProcessor。
<mvc:annotation-driven/>相当于注册了DefaultAnnotationHandlerMapping和AnnotationMethodHandlerAdapter两个bean,配置一些messageconverter。即解决了@Controller注解的使用前提配置
声明:类中 @component 或者按层 @controler @service @respository
注入 属性中@Autowired 属于spring 或者@resource 属于j2ee
2、配置 必须set方法
<bean id="hessianHelloWorldImpl" class="com.impl.HessianHelloWorldImpl"></bean>
<bean id="test" class="com.test.Test">
<property name="helloWorld" ref="hessianHelloWorldImpl"></property>
</bean>