File tree Expand file tree Collapse file tree
src/main/java/com/baeldung/beanfactory Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,8 +5,8 @@ RemoteSystemsTempFiles/
55bin /
66.metadata /
77docs /* .autosave
8- docs /* .autosave
98.recommenders /
109build /
1110.gradle /
1211.DS_Store
12+ .idea /
Original file line number Diff line number Diff line change 1+ package com .baeldung .beanfactory ;
2+
3+ import org .springframework .beans .factory .BeanFactory ;
4+ import org .springframework .beans .factory .xml .XmlBeanFactory ;
5+ import org .springframework .core .io .ClassPathResource ;
6+ import org .springframework .core .io .Resource ;
7+
8+ public class BeanFactoryWithClassPathResource {
9+
10+ public void createBeanFactory () {
11+
12+ Resource res = new ClassPathResource ("spring-app.xml" );
13+ BeanFactory factory = new XmlBeanFactory (res );
14+ Employee emp = (Employee ) factory .getBean ("employee" );
15+ }
16+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .beanfactory ;
2+
3+ public class Employee {
4+
5+ private String name ;
6+ private int age ;
7+
8+ public Employee (String name , int age ) {
9+ this .name = name ;
10+ this .age = age ;
11+ }
12+
13+ public String getName () {
14+ return name ;
15+ }
16+
17+ public void setName (String name ) {
18+ this .name = name ;
19+ }
20+
21+ public int getAge () {
22+ return age ;
23+ }
24+
25+ public void setAge (int age ) {
26+ this .age = age ;
27+ }
28+ }
Original file line number Diff line number Diff line change 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-3.0.xsd" >
6+
7+ <bean id =" employee" class =" com.baeldung.beanfactory.Employee" >
8+ <constructor-arg name =" name" value =" Hello! My name is Java" />
9+ <constructor-arg name =" age" value =" 18" />
10+ </bean >
11+ </beans >
You can’t perform that action at this time.
0 commit comments