當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
Spring注解开发-属性依赖注入
生活随笔
收集整理的這篇文章主要介紹了
Spring注解开发-属性依赖注入
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
1、簡單的屬性注入。無需增加get/set方法
注意:@Value @Autowired它們可以修飾屬性,也可以修飾setter方法,如果寫在屬性上,就不需要提供setter方法。
2、復(fù)雜的屬性注入
3、如果要掃描多個包下的注解可以寫成以下:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"><!-- <context:annotation-config /> --><!-- 下面的配置作用是指定spring掃描的包,它包含了context:annotation-config的功能,所以在開發(fā)中一般就不需要在配置上面的 --><context:component-scan base-package="cn.nwtxxb.annatation,cn.nwtxxb.dao" /></beans>也可以要掃描的包名設(shè)置為cn.nwtxxb父包,那么就都可以掃描到了.
總結(jié)
以上是生活随笔為你收集整理的Spring注解开发-属性依赖注入的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Spring注解开发-Bean注册
- 下一篇: Spring注解开发-属性依赖注入指定名