Skip to content

Commit 361874d

Browse files
author
DianeDuan
committed
simplify demos
1 parent e84957c commit 361874d

17 files changed

Lines changed: 83 additions & 393 deletions

‎spring-core/src/main/java/com/baeldung/factorybean/FactoryBeanAppConfig.java‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,15 @@
66
@Configuration
77
public class FactoryBeanAppConfig {
88
@Bean
9-
public ToolFactory tool() {
9+
public ToolFactory toolFactory() {
1010
ToolFactory factory = new ToolFactory();
1111
factory.setFactoryId(7070);
1212
factory.setToolId(2);
13-
factory.setToolName("wrench");
14-
factory.setToolPrice(3.7);
1513
return factory;
1614
}
1715

1816
@Bean
19-
public Worker worker() throws Exception {
20-
Worker worker = new Worker();
21-
worker.setNumber("1002");
22-
worker.setTool(tool().getObject());
23-
return worker;
17+
public Tool tool() throws Exception {
18+
return toolFactory().getObject();
2419
}
2520
}

‎spring-core/src/main/java/com/baeldung/factorybean/InitializationToolFactory.java‎

Lines changed: 0 additions & 67 deletions
This file was deleted.

‎spring-core/src/main/java/com/baeldung/factorybean/NonSingleToolFactory.java‎

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
public class NonSingleToolFactory extends AbstractFactoryBean<Tool> {
66
private int factoryId;
77
private int toolId;
8-
private String toolName;
9-
private double toolPrice;
108

119
public NonSingleToolFactory() {
1210
setSingleton(false);
@@ -19,7 +17,7 @@ public Class<?> getObjectType() {
1917

2018
@Override
2119
protected Tool createInstance() throws Exception {
22-
return new Tool(toolId, toolName, toolPrice);
20+
return new Tool(toolId);
2321
}
2422

2523
public int getFactoryId() {
@@ -37,20 +35,4 @@ public int getToolId() {
3735
public void setToolId(int toolId) {
3836
this.toolId = toolId;
3937
}
40-
41-
public String getToolName() {
42-
return toolName;
43-
}
44-
45-
public void setToolName(String toolName) {
46-
this.toolName = toolName;
47-
}
48-
49-
public double getToolPrice() {
50-
return toolPrice;
51-
}
52-
53-
public void setToolPrice(double toolPrice) {
54-
this.toolPrice = toolPrice;
55-
}
5638
}

‎spring-core/src/main/java/com/baeldung/factorybean/PostConstructToolFactory.java‎

Lines changed: 0 additions & 68 deletions
This file was deleted.

‎spring-core/src/main/java/com/baeldung/factorybean/SingleToolFactory.java‎

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
public class SingleToolFactory extends AbstractFactoryBean<Tool> {
77
private int factoryId;
88
private int toolId;
9-
private String toolName;
10-
private double toolPrice;
119

1210
@Override
1311
public Class<?> getObjectType() {
@@ -16,7 +14,7 @@ public Class<?> getObjectType() {
1614

1715
@Override
1816
protected Tool createInstance() throws Exception {
19-
return new Tool(toolId, toolName, toolPrice);
17+
return new Tool(toolId);
2018
}
2119

2220
public int getFactoryId() {
@@ -34,20 +32,4 @@ public int getToolId() {
3432
public void setToolId(int toolId) {
3533
this.toolId = toolId;
3634
}
37-
38-
public String getToolName() {
39-
return toolName;
40-
}
41-
42-
public void setToolName(String toolName) {
43-
this.toolName = toolName;
44-
}
45-
46-
public double getToolPrice() {
47-
return toolPrice;
48-
}
49-
50-
public void setToolPrice(double toolPrice) {
51-
this.toolPrice = toolPrice;
52-
}
5335
}

‎spring-core/src/main/java/com/baeldung/factorybean/Tool.java‎

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@
22

33
public class Tool {
44
private int id;
5-
private String name;
6-
private double price;
75

86
public Tool() {
97
}
108

11-
public Tool(int id, String name, double price) {
9+
public Tool(int id) {
1210
this.id = id;
13-
this.name = name;
14-
this.price = price;
1511
}
1612

1713
public int getId() {
@@ -21,20 +17,4 @@ public int getId() {
2117
public void setId(int id) {
2218
this.id = id;
2319
}
24-
25-
public String getName() {
26-
return name;
27-
}
28-
29-
public void setName(String name) {
30-
this.name = name;
31-
}
32-
33-
public double getPrice() {
34-
return price;
35-
}
36-
37-
public void setPrice(double price) {
38-
this.price = price;
39-
}
4020
}

‎spring-core/src/main/java/com/baeldung/factorybean/ToolFactory.java‎

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
public class ToolFactory implements FactoryBean<Tool> {
66
private int factoryId;
77
private int toolId;
8-
private String toolName;
9-
private double toolPrice;
108

119
@Override
1210
public Tool getObject() throws Exception {
13-
return new Tool(toolId, toolName, toolPrice);
11+
return new Tool(toolId);
1412
}
1513

1614
@Override
@@ -38,20 +36,4 @@ public int getToolId() {
3836
public void setToolId(int toolId) {
3937
this.toolId = toolId;
4038
}
41-
42-
public String getToolName() {
43-
return toolName;
44-
}
45-
46-
public void setToolName(String toolName) {
47-
this.toolName = toolName;
48-
}
49-
50-
public double getToolPrice() {
51-
return toolPrice;
52-
}
53-
54-
public void setToolPrice(double toolPrice) {
55-
this.toolPrice = toolPrice;
56-
}
5739
}

‎spring-core/src/main/java/com/baeldung/factorybean/Worker.java‎

Lines changed: 0 additions & 30 deletions
This file was deleted.

‎spring-core/src/main/resources/factorybean-abstract-spring-ctx.xml‎

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,10 @@
66
<bean id="singleTool" class="com.baeldung.factorybean.SingleToolFactory">
77
<property name="factoryId" value="3001"/>
88
<property name="toolId" value="1"/>
9-
<property name="toolName" value="screwdriver"/>
10-
<property name="toolPrice" value="1.5"/>
119
</bean>
1210

1311
<bean id="nonSingleTool" class="com.baeldung.factorybean.NonSingleToolFactory">
1412
<property name="factoryId" value="3002"/>
1513
<property name="toolId" value="2"/>
16-
<property name="toolName" value="screwdriver"/>
17-
<property name="toolPrice" value="1.5"/>
18-
</bean>
19-
20-
<bean id="worker1" class="com.baeldung.factorybean.Worker">
21-
<property name="number" value="50001"/>
22-
<property name="tool" ref="singleTool"/>
23-
</bean>
24-
25-
<bean id="worker2" class="com.baeldung.factorybean.Worker">
26-
<property name="number" value="50002"/>
27-
<property name="tool" ref="singleTool"/>
28-
</bean>
29-
30-
<bean id="worker3" class="com.baeldung.factorybean.Worker">
31-
<property name="number" value="50003"/>
32-
<property name="tool" ref="nonSingleTool"/>
33-
</bean>
34-
35-
<bean id="worker4" class="com.baeldung.factorybean.Worker">
36-
<property name="number" value="50004"/>
37-
<property name="tool" ref="nonSingleTool"/>
3814
</bean>
3915
</beans>

‎spring-core/src/main/resources/factorybean-init-spring-ctx.xml‎

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)