第一步:加入jar包

第二步:创建配置文件

-申明javabean 配置

<?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:p="http://www.springframework.org/schema/p"  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">

    <bean >        

      <property name="name" value="amaker"/>    

      </bean>

</beans>

第三步:获取bean工厂

Resource r = new ClassPathResource("applicationContext.xml");

BeanFactory factory = new XmlBeanFactory(r);

第四步:获取对象 HelloWorld h =(HelloWorld) factory.getBean("hw");

相关文章:

  • 2021-07-09
  • 2021-12-04
  • 2021-09-02
  • 2021-11-30
  • 2021-10-05
  • 2022-01-03
  • 2021-08-05
  • 2021-11-11
猜你喜欢
  • 2022-12-23
  • 2021-06-12
  • 2021-08-21
  • 2021-12-23
  • 2022-12-23
  • 2021-11-14
  • 2021-12-29
相关资源
相似解决方案