Spring 配置自动扫描spring bean配置

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/tx 
    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/aop 
    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"
    default-autowire="byName" default-lazy-init="true">

    <context:annotation-config />
    <context:component-scan base-package="com.wolfgang"></context:component-scan>

这样在类中

@Service("xxx")

写在service类的类定义上面,注入dao的地方

@Resource

private IxxxDao xxdao

在IxxxDao接口实现的类定义上方,写上

@Repository("xxdao")

xxxDaoImpl implements IXXXDao

原文地址:https://www.cnblogs.com/unixshell/p/3417212.html