applicationContext.xml配置文件加入:
<context:annotation-config/>
作用是隱式地向 Spring 容器註冊
AutowiredAnnotationBeanPostProcessor、CommonAnnotationBeanPostProcessor、
PersistenceAnnotationBeanPostProcessor 以及 RequiredAnnotationBeanPostProcessor 這 4 個BeanPostProcessor。
註冊這4個 BeanPostProcessor的作用,就是爲了你的系統能夠識別相應的註解。
<!-- 設置需要進行Spring註解掃描的類包 -->
<context:component-scan base-package="xx.xx" /> 可以用*代表所有
@Service()
publicclass ServiceImpl implements Service
調用時:
@Resource()
private Service Service;
這樣的話就能實現自動注入了
@Service一般用來定義Service層 dao,action都有對應的註解網上可查
這3種上面還有一種通用的不好定義組建類別時可用