Removed evaluation article (Dependency Injection) from master branch.

This commit is contained in:
gschambial 2017-11-13 22:48:09 +05:30
parent d03198a85f
commit 416bd4a9d5
36 changed files with 0 additions and 868 deletions

View File

@ -1,10 +0,0 @@
package com.baeldung.di.constructor.config;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@ComponentScan(basePackages = { "com.baeldung.di.constructor.model.autowire" })
public class SpringAutowireConstructorContext {
}

View File

@ -1,28 +0,0 @@
package com.baeldung.di.constructor.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.baeldung.di.constructor.model.bean.Computer;
import com.baeldung.di.constructor.model.bean.Memory;
import com.baeldung.di.constructor.model.bean.Processor;
@Configuration
public class SpringBeanConstructorContext {
@Bean
public Computer computer() {
return new Computer(processor(), memory());
}
@Bean
public Processor processor() {
return new Processor();
}
@Bean
public Memory memory() {
return new Memory();
}
}

View File

@ -1,32 +0,0 @@
package com.baeldung.di.constructor.factory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import com.baeldung.di.constructor.config.SpringAutowireConstructorContext;
import com.baeldung.di.constructor.model.autowire.Computer;
public class ComputerAutowireFactory {
public static void main(String[] args) {
// Create Spring Application Context
ApplicationContext context = new AnnotationConfigApplicationContext(SpringAutowireConstructorContext.class);
// Get Spring bean "computer" created
Computer computer = (Computer) context.getBean("computer");
System.out.println("---------------- Constructor Injection via @Autowire------------------");
System.out.println("Processor cores : " + computer.getProcessor()
.getCores());
System.out.println("Processor frequency : " + computer.getProcessor()
.getFrequency());
System.out.println("Memory Size in GB : " + computer.getMemory()
.getSizeInGb());
System.out.println("Memory format : " + computer.getMemory()
.getFormat());
System.out.println("---------------- Constructor Injection via @Autowire------------------");
// Close Spring Application Context
((ConfigurableApplicationContext) context).close();
}
}

View File

@ -1,33 +0,0 @@
package com.baeldung.di.constructor.factory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import com.baeldung.di.constructor.config.SpringBeanConstructorContext;
import com.baeldung.di.constructor.model.bean.Computer;
public class ComputerBeanFactory {
public static void main(String[] args) {
// Create Spring Application Context
ApplicationContext context = new AnnotationConfigApplicationContext(SpringBeanConstructorContext.class);
// Get Spring bean "computer" created
Computer computer = (Computer) context.getBean("computer");
System.out.println("---------------- Constructor Injection via @Bean ------------------");
System.out.println("Processor cores : " + computer.getProcessor()
.getCores());
System.out.println("Processor frequency : " + computer.getProcessor()
.getFrequency());
System.out.println("Memory Size in GB : " + computer.getMemory()
.getSizeInGb());
System.out.println("Memory format : " + computer.getMemory()
.getFormat());
System.out.println("---------------- Constructor Injection via @Bean ------------------");
// Close Spring Application Context
((ConfigurableApplicationContext) context).close();
}
}

View File

@ -1,33 +0,0 @@
package com.baeldung.di.constructor.factory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.baeldung.di.constructor.model.xml.Computer;
public class ComputerXmlFactory {
public static void main(String[] args) {
// Create Spring Application Context
ApplicationContext context = new ClassPathXmlApplicationContext("application-di-constructor-context.xml");
// Get Spring bean "computer" created
Computer computer = (Computer) context.getBean("computer");
System.out.println("---------------- Constructor Injection via XML ------------------");
System.out.println("Processor cores : " + computer.getProcessor()
.getCores());
System.out.println("Processor frequency : " + computer.getProcessor()
.getFrequency());
System.out.println("Memory Size in GB : " + computer.getMemory()
.getSizeInGb());
System.out.println("Memory format : " + computer.getMemory()
.getFormat());
System.out.println("---------------- Constructor Injection via XML ------------------");
// Close Spring Application Context
((ConfigurableApplicationContext) context).close();
}
}

View File

@ -1,34 +0,0 @@
package com.baeldung.di.constructor.model.autowire;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class Computer {
private Processor processor;
private Memory memory;
@Autowired
public Computer(Processor processor, Memory memory) {
this.processor = processor;
this.memory = memory;
}
public Processor getProcessor() {
return processor;
}
public void setProcessor(Processor processor) {
this.processor = processor;
}
public Memory getMemory() {
return memory;
}
public void setMemory(Memory memory) {
this.memory = memory;
}
}

View File

@ -1,19 +0,0 @@
package com.baeldung.di.constructor.model.autowire;
import org.springframework.stereotype.Component;
@Component
public class Memory {
private Integer sizeInGb = 16;
private String format = "DDR3";
public Integer getSizeInGb() {
return sizeInGb;
}
public String getFormat() {
return format;
}
}

View File

@ -1,19 +0,0 @@
package com.baeldung.di.constructor.model.autowire;
import org.springframework.stereotype.Component;
@Component
public class Processor {
private Integer cores = 2;
private Double frequency = 1.4;
public Integer getCores() {
return cores;
}
public Double getFrequency() {
return frequency;
}
}

View File

@ -1,29 +0,0 @@
package com.baeldung.di.constructor.model.bean;
public class Computer {
private Processor processor;
private Memory memory;
public Computer(Processor processor, Memory memory) {
this.processor = processor;
this.memory = memory;
}
public Processor getProcessor() {
return processor;
}
public void setProcessor(Processor processor) {
this.processor = processor;
}
public Memory getMemory() {
return memory;
}
public void setMemory(Memory memory) {
this.memory = memory;
}
}

View File

@ -1,16 +0,0 @@
package com.baeldung.di.constructor.model.bean;
public class Memory {
private Integer sizeInGb = 16;
private String format = "DDR3";
public Integer getSizeInGb() {
return sizeInGb;
}
public String getFormat() {
return format;
}
}

View File

@ -1,16 +0,0 @@
package com.baeldung.di.constructor.model.bean;
public class Processor {
private Integer cores = 2;
private Double frequency = 1.4;
public Integer getCores() {
return cores;
}
public Double getFrequency() {
return frequency;
}
}

View File

@ -1,29 +0,0 @@
package com.baeldung.di.constructor.model.xml;
public class Computer {
private Processor processor;
private Memory memory;
public Computer(Processor processor, Memory memory) {
this.processor = processor;
this.memory = memory;
}
public Processor getProcessor() {
return processor;
}
public void setProcessor(Processor processor) {
this.processor = processor;
}
public Memory getMemory() {
return memory;
}
public void setMemory(Memory memory) {
this.memory = memory;
}
}

View File

@ -1,20 +0,0 @@
package com.baeldung.di.constructor.model.xml;
public class Memory {
private Integer sizeInGb = 16;
private String format = "DDR3";
public Memory() {
}
public Integer getSizeInGb() {
return sizeInGb;
}
public String getFormat() {
return format;
}
}

View File

@ -1,16 +0,0 @@
package com.baeldung.di.constructor.model.xml;
public class Processor {
private Integer cores = 2;
private Double frequency = 1.4;
public Integer getCores() {
return cores;
}
public Double getFrequency() {
return frequency;
}
}

View File

@ -1,10 +0,0 @@
package com.baeldung.di.setter.config;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@ComponentScan(basePackages = { "com.baeldung.di.setter.model.autowire" })
public class SpringAutowireSetterContext {
}

View File

@ -1,31 +0,0 @@
package com.baeldung.di.setter.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.baeldung.di.setter.model.bean.Computer;
import com.baeldung.di.setter.model.bean.Memory;
import com.baeldung.di.setter.model.bean.Processor;
@Configuration
public class SpringBeanSetterContext {
@Bean
public Computer computer() {
Computer computer = new Computer();
computer.setProcessor(processor());
computer.setMemory(memory());
return computer;
}
@Bean
public Processor processor() {
return new Processor();
}
@Bean
public Memory memory() {
return new Memory();
}
}

View File

@ -1,32 +0,0 @@
package com.baeldung.di.setter.factory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import com.baeldung.di.setter.config.SpringAutowireSetterContext;
import com.baeldung.di.setter.model.autowire.Computer;
public class ComputerAutowireFactory {
public static void main(String[] args) {
// Create Spring Application Context
ApplicationContext context = new AnnotationConfigApplicationContext(SpringAutowireSetterContext.class);
// Get Spring bean "computer" created
Computer computer = (Computer) context.getBean("computer");
System.out.println("---------------- Setter Injection via @Autowire ------------------");
System.out.println("Processor cores : " + computer.getProcessor()
.getCores());
System.out.println("Processor frequency : " + computer.getProcessor()
.getFrequency());
System.out.println("Memory Size in GB : " + computer.getMemory()
.getSizeInGb());
System.out.println("Memory format : " + computer.getMemory()
.getFormat());
System.out.println("---------------- Setter Injection via @Autowire ------------------");
// Close Spring Application Context
((ConfigurableApplicationContext) context).close();
}
}

View File

@ -1,33 +0,0 @@
package com.baeldung.di.setter.factory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import com.baeldung.di.setter.config.SpringBeanSetterContext;
import com.baeldung.di.setter.model.bean.Computer;
public class ComputerBeanFactory {
public static void main(String[] args) {
// Create Spring Application Context
ApplicationContext context = new AnnotationConfigApplicationContext(SpringBeanSetterContext.class);
// Get Spring bean "computer" created
Computer computer = (Computer) context.getBean("computer");
System.out.println("---------------- Setter Injection via @Bean ------------------");
System.out.println("Processor cores : " + computer.getProcessor()
.getCores());
System.out.println("Processor frequency : " + computer.getProcessor()
.getFrequency());
System.out.println("Memory Size in GB : " + computer.getMemory()
.getSizeInGb());
System.out.println("Memory format : " + computer.getMemory()
.getFormat());
System.out.println("---------------- Setter Injection via @Bean ------------------");
// Close Spring Application Context
((ConfigurableApplicationContext) context).close();
}
}

View File

@ -1,32 +0,0 @@
package com.baeldung.di.setter.factory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.baeldung.di.setter.model.xml.Computer;
public class ComputerXmlFactory {
public static void main(String[] args) {
// Create Spring Application Context
ApplicationContext context = new ClassPathXmlApplicationContext("application-setter-context.xml");
// Get Spring bean "computer" created
Computer computer = (Computer) context.getBean("computer");
System.out.println("---------------- Setter Injection via XML ------------------");
System.out.println("Processor cores : " + computer.getProcessor()
.getCores());
System.out.println("Processor frequency : " + computer.getProcessor()
.getFrequency());
System.out.println("Memory Size in GB : " + computer.getMemory()
.getSizeInGb());
System.out.println("Memory format : " + computer.getMemory()
.getFormat());
System.out.println("---------------- Setter Injection via XML ------------------");
// Close Spring Application Context
((ConfigurableApplicationContext) context).close();
}
}

View File

@ -1,30 +0,0 @@
package com.baeldung.di.setter.model.autowire;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class Computer {
private Processor processor;
private Memory memory;
public Processor getProcessor() {
return processor;
}
@Autowired
public void setProcessor(Processor processor) {
this.processor = processor;
}
public Memory getMemory() {
return memory;
}
@Autowired
public void setMemory(Memory memory) {
this.memory = memory;
}
}

View File

@ -1,19 +0,0 @@
package com.baeldung.di.setter.model.autowire;
import org.springframework.stereotype.Component;
@Component
public class Memory {
private Integer sizeInGb = 16;
private String format = "DDR3";
public Integer getSizeInGb() {
return sizeInGb;
}
public String getFormat() {
return format;
}
}

View File

@ -1,19 +0,0 @@
package com.baeldung.di.setter.model.autowire;
import org.springframework.stereotype.Component;
@Component
public class Processor {
private Integer cores = 2;
private Double frequency = 1.4;
public Integer getCores() {
return cores;
}
public Double getFrequency() {
return frequency;
}
}

View File

@ -1,24 +0,0 @@
package com.baeldung.di.setter.model.bean;
public class Computer {
private Processor processor;
private Memory memory;
public Processor getProcessor() {
return processor;
}
public void setProcessor(Processor processor) {
this.processor = processor;
}
public Memory getMemory() {
return memory;
}
public void setMemory(Memory memory) {
this.memory = memory;
}
}

View File

@ -1,17 +0,0 @@
package com.baeldung.di.setter.model.bean;
public class Memory {
private Integer sizeInGb = 16;
private String format = "DDR3";
//
public Integer getSizeInGb() {
return sizeInGb;
}
public String getFormat() {
return format;
}
}

View File

@ -1,16 +0,0 @@
package com.baeldung.di.setter.model.bean;
public class Processor {
private Integer cores = 2;
private Double frequency = 1.4;
public Integer getCores() {
return cores;
}
public Double getFrequency() {
return frequency;
}
}

View File

@ -1,24 +0,0 @@
package com.baeldung.di.setter.model.xml;
public class Computer {
private Processor processor;
private Memory memory;
public Processor getProcessor() {
return processor;
}
public void setProcessor(Processor processor) {
this.processor = processor;
}
public Memory getMemory() {
return memory;
}
public void setMemory(Memory memory) {
this.memory = memory;
}
}

View File

@ -1,20 +0,0 @@
package com.baeldung.di.setter.model.xml;
public class Memory {
private Integer sizeInGb = 16;
private String format = "DDR3";
public Memory() {
}
public Integer getSizeInGb() {
return sizeInGb;
}
public String getFormat() {
return format;
}
}

View File

@ -1,16 +0,0 @@
package com.baeldung.di.setter.model.xml;
public class Processor {
private Integer cores = 2;
private Double frequency = 1.4;
public Integer getCores() {
return cores;
}
public Double getFrequency() {
return frequency;
}
}

View File

@ -1,23 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
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
">
<!-- Define your application beans here. They will be available to the beans
defined in your web-context because it is a sub-context. Beans defined in
the web-context will not be available in the application context. -->
<bean id="computer" class="com.baeldung.di.constructor.model.xml.Computer">
<constructor-arg ref="processor" />
<constructor-arg ref="memory" />
</bean>
<bean id="processor" class="com.baeldung.di.constructor.model.xml.Processor" />
<bean id="memory" class="com.baeldung.di.constructor.model.xml.Memory" />
</beans>

View File

@ -1,22 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
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
">
<!-- Define your application beans here. They will be available to the beans
defined in your web-context because it is a sub-context. Beans defined in
the web-context will not be available in the application context. -->
<bean id="computer" class="com.baeldung.di.setter.model.xml.Computer">
<property name="processor" ref="processor"></property>
<property name="memory" ref="memory"></property>
</bean>
<bean id="processor" class="com.baeldung.di.setter.model.xml.Processor" />
<bean id="memory" class="com.baeldung.di.setter.model.xml.Memory" />
</beans>

View File

@ -1,28 +0,0 @@
package com.baeldung.di.constructor;
import static org.junit.Assert.assertNotNull;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import com.baeldung.di.constructor.config.SpringAutowireConstructorContext;
import com.baeldung.di.constructor.model.autowire.Computer;
public class AutowireAnnotationInjectionUnitTest {
private ApplicationContext applicationContext;
@Before
public void setUp() throws Exception {
applicationContext = new AnnotationConfigApplicationContext(SpringAutowireConstructorContext.class);
}
@Test
public void getComputer_() {
final Computer computer = applicationContext.getBean("computer", Computer.class);
assertNotNull(computer);
}
}

View File

@ -1,28 +0,0 @@
package com.baeldung.di.constructor;
import static org.junit.Assert.assertNotNull;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import com.baeldung.di.constructor.config.SpringBeanConstructorContext;
import com.baeldung.di.constructor.model.bean.Computer;
public class BeanAnnotationInjectionUnitTest {
private ApplicationContext applicationContext;
@Before
public void setUp() throws Exception {
applicationContext = new AnnotationConfigApplicationContext(SpringBeanConstructorContext.class);
}
@Test
public void getComputer_() {
final Computer computer = applicationContext.getBean("computer", Computer.class);
assertNotNull(computer);
}
}

View File

@ -1,27 +0,0 @@
package com.baeldung.di.constructor;
import static org.junit.Assert.assertNotNull;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.baeldung.di.constructor.model.xml.Computer;
public class XmlInjectionUnitTest {
private ApplicationContext applicationContext;
@Before
public void setUp() throws Exception {
applicationContext = new ClassPathXmlApplicationContext("application-di-constructor-context.xml");
}
@Test
public void getComputer_() {
final Computer computer = applicationContext.getBean("computer", Computer.class);
assertNotNull(computer);
}
}

View File

@ -1,28 +0,0 @@
package com.baeldung.di.setter;
import static org.junit.Assert.assertNotNull;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import com.baeldung.di.setter.config.SpringAutowireSetterContext;
import com.baeldung.di.setter.model.autowire.Computer;
public class AutowireAnnotationInjectionUnitTest {
private ApplicationContext applicationContext;
@Before
public void setUp() throws Exception {
applicationContext = new AnnotationConfigApplicationContext(SpringAutowireSetterContext.class);
}
@Test
public void getComputer_() {
final Computer computer = applicationContext.getBean("computer", Computer.class);
assertNotNull(computer);
}
}

View File

@ -1,28 +0,0 @@
package com.baeldung.di.setter;
import static org.junit.Assert.assertNotNull;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import com.baeldung.di.setter.config.SpringBeanSetterContext;
import com.baeldung.di.setter.model.bean.Computer;
public class BeanAnnotationInjectionUnitTest {
private ApplicationContext applicationContext;
@Before
public void setUp() throws Exception {
applicationContext = new AnnotationConfigApplicationContext(SpringBeanSetterContext.class);
}
@Test
public void getComputer_() {
final Computer computer = applicationContext.getBean("computer", Computer.class);
assertNotNull(computer);
}
}

View File

@ -1,27 +0,0 @@
package com.baeldung.di.setter;
import static org.junit.Assert.assertNotNull;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.baeldung.di.setter.model.xml.Computer;
public class XmlInjectionUnitTest {
private ApplicationContext applicationContext;
@Before
public void setUp() throws Exception {
applicationContext = new ClassPathXmlApplicationContext("application-di-setter-context.xml");
}
@Test
public void getComputer_() {
final Computer computer = applicationContext.getBean("computer", Computer.class);
assertNotNull(computer);
}
}