BAEL-453 some improvments, formatting etc.

This commit is contained in:
Marek Lewandowski 2016-11-21 22:01:05 +01:00
parent d6daf8235c
commit b8ade6f6da
15 changed files with 21 additions and 14 deletions

View File

@ -5,6 +5,7 @@ import org.springframework.context.annotation.Configuration;
@Configuration @Configuration
public class FactoryBeanAppConfig { public class FactoryBeanAppConfig {
@Bean @Bean
public ToolFactory tool() { public ToolFactory tool() {
ToolFactory factory = new ToolFactory(); ToolFactory factory = new ToolFactory();

View File

@ -7,6 +7,7 @@ import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
public class InitializationToolFactory implements FactoryBean<Tool>, InitializingBean { public class InitializationToolFactory implements FactoryBean<Tool>, InitializingBean {
private int factoryId; private int factoryId;
private int toolId; private int toolId;
private String toolName; private String toolName;

View File

@ -3,6 +3,7 @@ package com.baeldung.factorybean;
import org.springframework.beans.factory.config.AbstractFactoryBean; import org.springframework.beans.factory.config.AbstractFactoryBean;
public class NonSingleToolFactory extends AbstractFactoryBean<Tool> { public class NonSingleToolFactory extends AbstractFactoryBean<Tool> {
private int factoryId; private int factoryId;
private int toolId; private int toolId;
private String toolName; private String toolName;

View File

@ -8,6 +8,7 @@ import org.springframework.beans.factory.FactoryBean;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
public class PostConstructToolFactory implements FactoryBean<Tool> { public class PostConstructToolFactory implements FactoryBean<Tool> {
private int factoryId; private int factoryId;
private int toolId; private int toolId;
private String toolName; private String toolName;

View File

@ -4,6 +4,7 @@ import org.springframework.beans.factory.config.AbstractFactoryBean;
//no need to set singleton property because default value is true //no need to set singleton property because default value is true
public class SingleToolFactory extends AbstractFactoryBean<Tool> { public class SingleToolFactory extends AbstractFactoryBean<Tool> {
private int factoryId; private int factoryId;
private int toolId; private int toolId;
private String toolName; private String toolName;

View File

@ -1,13 +1,11 @@
package com.baeldung.factorybean; package com.baeldung.factorybean;
public class Tool { public class Tool {
private int id; private int id;
private String name; private String name;
private double price; private double price;
public Tool() {
}
public Tool(int id, String name, double price) { public Tool(int id, String name, double price) {
this.id = id; this.id = id;
this.name = name; this.name = name;

View File

@ -3,6 +3,7 @@ package com.baeldung.factorybean;
import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.FactoryBean;
public class ToolFactory implements FactoryBean<Tool> { public class ToolFactory implements FactoryBean<Tool> {
private int factoryId; private int factoryId;
private int toolId; private int toolId;
private String toolName; private String toolName;

View File

@ -1,11 +1,11 @@
package com.baeldung.factorybean; package com.baeldung.factorybean;
public class Worker { public class Worker {
private String number; private String number;
private Tool tool; private Tool tool;
public Worker() { public Worker() {}
}
public Worker(String number, Tool tool) { public Worker(String number, Tool tool) {
this.number = number; this.number = number;

View File

@ -9,6 +9,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;
public class AbstractFactoryBeanTest { public class AbstractFactoryBeanTest {
@Test @Test
public void testSingleToolFactory() { public void testSingleToolFactory() {
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:factorybean-abstract-spring-ctx.xml"); ApplicationContext context = new ClassPathXmlApplicationContext("classpath:factorybean-abstract-spring-ctx.xml");

View File

@ -5,6 +5,7 @@ import org.springframework.beans.factory.BeanCreationException;
import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;
public class FactoryBeanInitializeTest { public class FactoryBeanInitializeTest {
@Test(expected = BeanCreationException.class) @Test(expected = BeanCreationException.class)
public void testInitializationToolFactory() { public void testInitializationToolFactory() {
new ClassPathXmlApplicationContext("classpath:factorybean-init-spring-ctx.xml"); new ClassPathXmlApplicationContext("classpath:factorybean-init-spring-ctx.xml");

View File

@ -9,6 +9,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;
public class FactoryBeanTest { public class FactoryBeanTest {
@Test @Test
public void testConstructWorkerByXml() { public void testConstructWorkerByXml() {
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:factorybean-spring-ctx.xml"); ApplicationContext context = new ClassPathXmlApplicationContext("classpath:factorybean-spring-ctx.xml");