提交 a8039013 编写于 作者: 踏雪无痕ouo's avatar 踏雪无痕ouo

spring_Ioc

上级 7e1026f2
......@@ -10,6 +10,7 @@ public class Demo {
ClassPathXmlApplicationContext app = new ClassPathXmlApplicationContext("applicationContext.xml");
StudentDao studentDao = (StudentDao)app.getBean("studentDao");
StudentDao studentDao2 = (StudentDao)app.getBean("studentDao");
Student student = studentDao.getStudentById(33);
......
......@@ -5,6 +5,10 @@ import com.wsstart.domain.Student;
public class StudentDaoImpl implements StudentDao {
public StudentDaoImpl() {
System.out.println("StudentDaoImpl创建了");
}
public Student getStudentById(int id){
return new Student("沃柑ouo",33,33);
}
......
......@@ -4,5 +4,5 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean class="com.wsstart.dao.impl.StudentDaoImpl" id="studentDao"></bean>
<bean class="com.wsstart.dao.impl.StudentDaoImpl" id="studentDao" scope="singleton"></bean>
</beans>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册