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;
|
||||
|
@ -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…
x
Reference in New Issue
Block a user