SpringMVC的(基本)注入与使用
SpringMVC的(基本)注入与使用
在maven导入关于SpringMVC的jar包后,即可开始使用Spring框架.
使用SpringMVC框架前,要导入applicationContext.xml文件到src/main/resources目录下
applicationContext.xml的内容如下 :
准备工作完毕,可以开始使用SpringMVC框架
一 . 配置XML文件
application.xml中,在根节点下添加<bean></bean>元素,该节点中需要配置id和class属性. id属性自由取名,但一般为类的首字母小写.而class属性为类的全路径.
二 . 利用SpringMVC构造对象
在xml文件中配置好的类的对象后,即可通过SpringMVC构造对象.
1 . 加载application.xml文件没获得SpringMVC的配置
2 . 通过AbstractApplicationContext类创造实例对象 ( getBean("A","B") A为在xml文件中配置的id B为类的class属性 )