applicationContext.xml 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. http://www.springframework.org/schema/beans/spring-beans.xsd">
  6. <!--创建spring配置文件,配置对应的类,作为spring管理的bean-->
  7. <!--
  8. bean是专门指在IOC容器里的对象
  9. bean标签:表示配置bean
  10. id属性:是给bean取个名字
  11. class属性:表示给bean定义实际的类型
  12. name属性:为这个bean取别名
  13. scope属性:定义bean的作用范围,可以选择:单例(singleton)、非单例(prototype),默认scope属性的值是singleton单例模式
  14. request
  15. session
  16. application
  17. websocket....
  18. -->
  19. <bean id="UserMapper" name="userMapper,userMapperImpl,userMapperImpl1" class="com.sf.ioc.mapper.UserMapperImpl" scope="singleton" />
  20. <!--配置service和mapper之间的关系-->
  21. <bean id="UserService" name="userService,userServiceImpl1" class="com.sf.ioc.service.impl.UserServiceImpl" scope="prototype">
  22. <!--
  23. property标签:配置当前的bean的属性
  24. name属性:对应着具体的属性变量
  25. ref属性:对应着要参照的是哪一个bean
  26. -->
  27. <property name="userMapper" ref="UserMapper"/>
  28. </bean>
  29. <bean id="StudentService" name="studentService"
  30. class="com.sf.ioc.factory.StudentServiceFactory" factory-method="getStudentService" />
  31. <!--先创建工厂bean-->
  32. <bean id="productServiceFactory" class="com.sf.ioc.factory.ProductServiceFactory"/>
  33. <!--创建productServiceBean的时候,引入工厂bean-->
  34. <bean id="ProductService" name="productService"
  35. factory-bean="productServiceFactory" factory-method="getProductService"/>
  36. <!--
  37. init-method属性:表示这个bean初始化后立刻要执行的方法
  38. destroy-method属性:表示这个bean在销毁之前要执行的方法
  39. -->
  40. <bean id="TeaService" name="teaService"
  41. class="com.sf.beanLifeCycle.service.impl.TeaServiceImpl"/>
  42. </beans>