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
public class FactoryBeanAppConfig {
@Bean
public ToolFactory tool() {
ToolFactory factory = new ToolFactory();

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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"/>

View File

@ -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"/>

View File

@ -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/>

View File

@ -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"/>

View File

@ -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");

View File

@ -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");

View File

@ -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");