1、web.xml設置監聽
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:SpringConfig*.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
2、在springconfig.xml中設置自動需要掃描的包
<context:component-scan base-package="com.jmd" />
3、在需要加載成bean的地方 使用註解方式
@Controller通知spring進行默認加載。