JavaEE实验六 :bean的装配
实验目的:
通过基于annotation的装配方式装配bean实例,来达到熟练掌握Spring中bean的装配方式的目的。
实验内容:
定义一个学生类Student,在类中定义(sno,sname,major(专业))三个属性。用三层架构模式模拟添加学生的操作。用注解方式完成bean的装配,在应用程序中获取bean对象,并调用方法完成模拟添加学生。
实验代码:
ApplicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!-- 使用 context 命名空间 ,在配置文件中开启相应的注解处理器 -->
<context:component-scan base-package="com.itheima" />
</beans>
Student
package com.itheima.entity;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.<