Baeldung eclipse formatter added.

This commit is contained in:
gschambial 2017-11-10 18:14:31 +05:30
parent 8c8af4e9bf
commit b2dead9484
30 changed files with 366 additions and 347 deletions

View File

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

View File

@ -10,19 +10,19 @@ import com.baeldung.di.constructor.model.bean.Processor;
@Configuration @Configuration
public class SpringBeanConstructorContext { public class SpringBeanConstructorContext {
@Bean @Bean
public Computer computer(){ public Computer computer() {
return new Computer(processor(), memory()); return new Computer(processor(), memory());
} }
@Bean @Bean
public Processor processor(){ public Processor processor() {
return new Processor(); return new Processor();
} }
@Bean @Bean
public Memory memory(){ public Memory memory() {
return new Memory(); return new Memory();
} }
} }

View File

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

View File

@ -9,21 +9,25 @@ import com.baeldung.di.constructor.model.bean.Computer;
public class ComputerBeanFactory { public class ComputerBeanFactory {
public static void main(String[] args) { public static void main(String[] args) {
// Create Spring Application Context // Create Spring Application Context
ApplicationContext context = new AnnotationConfigApplicationContext(SpringBeanConstructorContext.class); ApplicationContext context = new AnnotationConfigApplicationContext(SpringBeanConstructorContext.class);
// Get Spring bean "computer" created // Get Spring bean "computer" created
Computer computer = (Computer) context.getBean("computer"); Computer computer = (Computer) context.getBean("computer");
System.out.println("---------------- Constructor Injection via @Bean ------------------"); System.out.println("---------------- Constructor Injection via @Bean ------------------");
System.out.println("Processor cores : " + computer.getProcessor().getCores()); System.out.println("Processor cores : " + computer.getProcessor()
System.out.println("Processor frequency : " + computer.getProcessor().getFrequency()); .getCores());
System.out.println("Memory Size in GB : " + computer.getMemory().getSizeInGb()); System.out.println("Processor frequency : " + computer.getProcessor()
System.out.println("Memory format : " + computer.getMemory().getFormat()); .getFrequency());
System.out.println("---------------- Constructor Injection via @Bean ------------------"); 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 // Close Spring Application Context
((ConfigurableApplicationContext) context).close(); ((ConfigurableApplicationContext) context).close();
} }
} }

View File

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

View File

@ -6,29 +6,29 @@ import org.springframework.stereotype.Component;
@Component @Component
public class Computer { public class Computer {
private Processor processor; private Processor processor;
private Memory memory; private Memory memory;
@Autowired @Autowired
public Computer(Processor processor, Memory memory) { public Computer(Processor processor, Memory memory) {
this.processor = processor; this.processor = processor;
this.memory = memory; this.memory = memory;
} }
public Processor getProcessor() { public Processor getProcessor() {
return processor; return processor;
} }
public void setProcessor(Processor processor) { public void setProcessor(Processor processor) {
this.processor = processor; this.processor = processor;
} }
public Memory getMemory() { public Memory getMemory() {
return memory; return memory;
} }
public void setMemory(Memory memory) { public void setMemory(Memory memory) {
this.memory = memory; this.memory = memory;
} }
} }

View File

@ -5,15 +5,15 @@ import org.springframework.stereotype.Component;
@Component @Component
public class Memory { public class Memory {
private Integer sizeInGb = 16; private Integer sizeInGb = 16;
private String format = "DDR3"; private String format = "DDR3";
public Integer getSizeInGb() { public Integer getSizeInGb() {
return sizeInGb; return sizeInGb;
} }
public String getFormat() { public String getFormat() {
return format; return format;
} }
} }

View File

@ -5,15 +5,15 @@ import org.springframework.stereotype.Component;
@Component @Component
public class Processor { public class Processor {
private Integer cores = 2; private Integer cores = 2;
private Double frequency = 1.4; private Double frequency = 1.4;
public Integer getCores() { public Integer getCores() {
return cores; return cores;
} }
public Double getFrequency() { public Double getFrequency() {
return frequency; return frequency;
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -10,22 +10,22 @@ import com.baeldung.di.setter.model.bean.Processor;
@Configuration @Configuration
public class SpringBeanSetterContext { public class SpringBeanSetterContext {
@Bean @Bean
public Computer computer(){ public Computer computer() {
Computer computer = new Computer(); Computer computer = new Computer();
computer.setProcessor(processor()); computer.setProcessor(processor());
computer.setMemory(memory()); computer.setMemory(memory());
return computer; return computer;
} }
@Bean @Bean
public Processor processor(){ public Processor processor() {
return new Processor(); return new Processor();
} }
@Bean @Bean
public Memory memory(){ public Memory memory() {
return new Memory(); return new Memory();
} }
} }

View File

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

View File

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

View File

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

View File

@ -6,25 +6,25 @@ import org.springframework.stereotype.Component;
@Component @Component
public class Computer { public class Computer {
private Processor processor; private Processor processor;
private Memory memory; private Memory memory;
public Processor getProcessor() { public Processor getProcessor() {
return processor; return processor;
} }
@Autowired @Autowired
public void setProcessor(Processor processor) { public void setProcessor(Processor processor) {
this.processor = processor; this.processor = processor;
} }
public Memory getMemory() { public Memory getMemory() {
return memory; return memory;
} }
@Autowired @Autowired
public void setMemory(Memory memory) { public void setMemory(Memory memory) {
this.memory = memory; this.memory = memory;
} }
} }

View File

@ -5,15 +5,15 @@ import org.springframework.stereotype.Component;
@Component @Component
public class Memory { public class Memory {
private Integer sizeInGb = 16; private Integer sizeInGb = 16;
private String format = "DDR3"; private String format = "DDR3";
public Integer getSizeInGb() { public Integer getSizeInGb() {
return sizeInGb; return sizeInGb;
} }
public String getFormat() { public String getFormat() {
return format; return format;
} }
} }

View File

@ -5,15 +5,15 @@ import org.springframework.stereotype.Component;
@Component @Component
public class Processor { public class Processor {
private Integer cores = 2; private Integer cores = 2;
private Double frequency = 1.4; private Double frequency = 1.4;
public Integer getCores() { public Integer getCores() {
return cores; return cores;
} }
public Double getFrequency() { public Double getFrequency() {
return frequency; return frequency;
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -13,7 +13,7 @@
<bean id="computer" class="com.baeldung.di.constructor.model.xml.Computer"> <bean id="computer" class="com.baeldung.di.constructor.model.xml.Computer">
<constructor-arg ref="processor"/> <constructor-arg ref="processor" />
<constructor-arg ref="memory" /> <constructor-arg ref="memory" />
</bean> </bean>