BAEL-453 some improvments, formatting etc.
This commit is contained in:
parent
d6daf8235c
commit
b8ade6f6da
|
@ -5,6 +5,7 @@ import org.springframework.context.annotation.Configuration;
|
|||
|
||||
@Configuration
|
||||
public class FactoryBeanAppConfig {
|
||||
|
||||
@Bean
|
||||
public ToolFactory tool() {
|
||||
ToolFactory factory = new ToolFactory();
|
||||
|
|
|
@ -7,6 +7,7 @@ import org.springframework.beans.factory.InitializingBean;
|
|||
import org.springframework.util.StringUtils;
|
||||
|
||||
public class InitializationToolFactory implements FactoryBean<Tool>, InitializingBean {
|
||||
|
||||
private int factoryId;
|
||||
private int toolId;
|
||||
private String toolName;
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.baeldung.factorybean;
|
|||
import org.springframework.beans.factory.config.AbstractFactoryBean;
|
||||
|
||||
public class NonSingleToolFactory extends AbstractFactoryBean<Tool> {
|
||||
|
||||
private int factoryId;
|
||||
private int toolId;
|
||||
private String toolName;
|
||||
|
|
|
@ -8,6 +8,7 @@ import org.springframework.beans.factory.FactoryBean;
|
|||
import org.springframework.util.StringUtils;
|
||||
|
||||
public class PostConstructToolFactory implements FactoryBean<Tool> {
|
||||
|
||||
private int factoryId;
|
||||
private int toolId;
|
||||
private String toolName;
|
||||
|
|
|
@ -4,6 +4,7 @@ import org.springframework.beans.factory.config.AbstractFactoryBean;
|
|||
|
||||
//no need to set singleton property because default value is true
|
||||
public class SingleToolFactory extends AbstractFactoryBean<Tool> {
|
||||
|
||||
private int factoryId;
|
||||
private int toolId;
|
||||
private String toolName;
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
package com.baeldung.factorybean;
|
||||
|
||||
public class Tool {
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
private double price;
|
||||
|
||||
public Tool() {
|
||||
}
|
||||
|
||||
public Tool(int id, String name, double price) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.baeldung.factorybean;
|
|||
import org.springframework.beans.factory.FactoryBean;
|
||||
|
||||
public class ToolFactory implements FactoryBean<Tool> {
|
||||
|
||||
private int factoryId;
|
||||
private int toolId;
|
||||
private String toolName;
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package com.baeldung.factorybean;
|
||||
|
||||
public class Worker {
|
||||
|
||||
private String number;
|
||||
private Tool tool;
|
||||
|
||||
public Worker() {
|
||||
}
|
||||
public Worker() {}
|
||||
|
||||
public Worker(String number, Tool tool) {
|
||||
this.number = number;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://www.springframework.org/schema/beans"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
xmlns="http://www.springframework.org/schema/beans"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<bean id="singleTool" class="com.baeldung.factorybean.SingleToolFactory">
|
||||
<property name="factoryId" value="3001"/>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://www.springframework.org/schema/beans"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
xmlns="http://www.springframework.org/schema/beans"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<bean id="initializationTool" class="com.baeldung.factorybean.InitializationToolFactory">
|
||||
<property name="factoryId" value="1010"/>
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns="http://www.springframework.org/schema/beans"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns="http://www.springframework.org/schema/beans"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
|
||||
|
||||
<context:annotation-config/>
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://www.springframework.org/schema/beans"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
xmlns="http://www.springframework.org/schema/beans"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<bean id="tool" class="com.baeldung.factorybean.ToolFactory">
|
||||
<property name="factoryId" value="9090"/>
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.springframework.context.ApplicationContext;
|
|||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
public class AbstractFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void testSingleToolFactory() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:factorybean-abstract-spring-ctx.xml");
|
||||
|
|
|
@ -5,6 +5,7 @@ import org.springframework.beans.factory.BeanCreationException;
|
|||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
public class FactoryBeanInitializeTest {
|
||||
|
||||
@Test(expected = BeanCreationException.class)
|
||||
public void testInitializationToolFactory() {
|
||||
new ClassPathXmlApplicationContext("classpath:factorybean-init-spring-ctx.xml");
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
|
|||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
public class FactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void testConstructWorkerByXml() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:factorybean-spring-ctx.xml");
|
||||
|
|
Loading…
Reference in New Issue