Spring学习笔记 (5)

Spring:

  1. 需要注入的属性写到配置文件中:

    如果属性为基础类型,需要有setter()方法,必须也写在包的类代码中,因为需要setter()方法

    如果属性为类,需要有无参构造方法,可不写在包的类代码中

  2. spring-config.xml的告知:

    在程序入口告知:

      对于测试入口:@ContextConfiguration("classpath:spring-config.xml")

      对于Servlet,在web.xml:

                 <init-param>

                 <param-name>contextConfigLocation</param-name>

             <param-value>classpath:spring-config.xml</param-value>

         </init-param>

逆天改命!我命由我不由天!
原文地址:https://www.cnblogs.com/huhewei/p/14034492.html