[BAEL-16662] Move articles out of spring-core and into spring-di and … (#7750)
* [BAEL-16662] Move articles out of spring-core and into spring-di and spring-core-2 * [BAEL-16662] Fixed required config classes * [BAEL-16662] - Removed unused dependencies from spring-core
This commit is contained in:
parent
6ee7181125
commit
8d6c2dc2ed
|
@ -1,3 +1,6 @@
|
|||
## Relevant Articles:
|
||||
|
||||
- [Understanding getBean() in Spring](https://www.baeldung.com/spring-getbean)
|
||||
- [Exploring the Spring BeanFactory API](http://www.baeldung.com/spring-beanfactory)
|
||||
- [How to use the Spring FactoryBean?](http://www.baeldung.com/spring-factorybean)
|
||||
- [Spring – Injecting Collections](http://www.baeldung.com/spring-injecting-collections)
|
||||
|
|
|
@ -14,6 +14,11 @@
|
|||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-beans</artifactId>
|
||||
|
|
|
@ -1,22 +1,12 @@
|
|||
### Relevant Articles:
|
||||
- [Wiring in Spring: @Autowired, @Resource and @Inject](http://www.baeldung.com/spring-annotations-resource-inject-autowire)
|
||||
- [Exploring the Spring BeanFactory API](http://www.baeldung.com/spring-beanfactory)
|
||||
- [How to use the Spring FactoryBean?](http://www.baeldung.com/spring-factorybean)
|
||||
- [Constructor Dependency Injection in Spring](http://www.baeldung.com/constructor-injection-in-spring)
|
||||
- [Constructor Injection in Spring with Lombok](http://www.baeldung.com/spring-injection-lombok)
|
||||
- [Introduction to Spring’s StreamUtils](http://www.baeldung.com/spring-stream-utils)
|
||||
- [XML-Based Injection in Spring](http://www.baeldung.com/spring-xml-injection)
|
||||
- [A Quick Guide to the Spring @Lazy Annotation](http://www.baeldung.com/spring-lazy-annotation)
|
||||
- [Injecting Prototype Beans into a Singleton Instance in Spring](http://www.baeldung.com/spring-inject-prototype-bean-into-singleton)
|
||||
- [@Lookup Annotation in Spring](http://www.baeldung.com/spring-lookup)
|
||||
- [BeanNameAware and BeanFactoryAware Interfaces in Spring](http://www.baeldung.com/spring-bean-name-factory-aware)
|
||||
- [Spring – Injecting Collections](http://www.baeldung.com/spring-injecting-collections)
|
||||
- [Access a File from the Classpath in a Spring Application](http://www.baeldung.com/spring-classpath-file-access)
|
||||
- [Controlling Bean Creation Order with @DependsOn Annotation](http://www.baeldung.com/spring-depends-on)
|
||||
- [Spring Autowiring of Generic Types](https://www.baeldung.com/spring-autowire-generics)
|
||||
- [Spring Application Context Events](https://www.baeldung.com/spring-context-events)
|
||||
- [Unsatisfied Dependency in Spring](https://www.baeldung.com/spring-unsatisfied-dependency)
|
||||
- [What is a Spring Bean?](https://www.baeldung.com/spring-bean)
|
||||
- [Spring PostConstruct and PreDestroy Annotations](https://www.baeldung.com/spring-postconstruct-predestroy)
|
||||
- [Guice vs Spring – Dependency Injection](https://www.baeldung.com/guice-spring-dependency-injection)
|
||||
- [Circular Dependencies in Spring](http://www.baeldung.com/circular-dependencies-in-spring)
|
||||
|
||||
|
|
|
@ -1,3 +1,11 @@
|
|||
### Relevant Articles
|
||||
|
||||
- [The Spring @Qualifier Annotation](https://www.baeldung.com/spring-qualifier-annotation)
|
||||
- [Constructor Dependency Injection in Spring](http://www.baeldung.com/constructor-injection-in-spring)
|
||||
- [Spring Autowiring of Generic Types](https://www.baeldung.com/spring-autowire-generics)
|
||||
- [Guice vs Spring – Dependency Injection](https://www.baeldung.com/guice-spring-dependency-injection)
|
||||
- [Injecting Prototype Beans into a Singleton Instance in Spring](http://www.baeldung.com/spring-inject-prototype-bean-into-singleton)
|
||||
- [@Lookup Annotation in Spring](http://www.baeldung.com/spring-lookup)
|
||||
- [Controlling Bean Creation Order with @DependsOn Annotation](http://www.baeldung.com/spring-depends-on)
|
||||
- [Unsatisfied Dependency in Spring](https://www.baeldung.com/spring-unsatisfied-dependency)
|
||||
- [Circular Dependencies in Spring](http://www.baeldung.com/circular-dependencies-in-spring)
|
||||
|
|
|
@ -9,18 +9,70 @@
|
|||
<name>spring-di</name>
|
||||
|
||||
<parent>
|
||||
<artifactId>parent-boot-2</artifactId>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-spring-5</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../parent-boot-2</relativePath>
|
||||
<relativePath>../parent-spring-5</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<!-- Spring -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-beans</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.inject</groupId>
|
||||
<artifactId>javax.inject</artifactId>
|
||||
<version>${javax.inject.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>${guava.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
<version>${spring-boot.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-test</artifactId>
|
||||
<version>${mockito.spring.boot.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>${commons.io.version}</version>
|
||||
</dependency>
|
||||
<!-- Spring -->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework</groupId>-->
|
||||
<!-- <artifactId>spring-context</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.annotation</groupId>
|
||||
|
@ -28,12 +80,12 @@
|
|||
<version>${annotation-api.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- test scoped -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- <!– test scoped –>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework</groupId>-->
|
||||
<!-- <artifactId>spring-test</artifactId>-->
|
||||
<!-- <scope>test</scope>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
@ -97,6 +149,14 @@
|
|||
<!-- Spring -->
|
||||
<org.springframework.version>5.0.6.RELEASE</org.springframework.version>
|
||||
<annotation-api.version>1.3.2</annotation-api.version>
|
||||
|
||||
<mockito.spring.boot.version>1.4.4.RELEASE</mockito.spring.boot.version>
|
||||
<javax.inject.version>1</javax.inject.version>
|
||||
<guava.version>20.0</guava.version>
|
||||
<commons.io.version>2.5</commons.io.version>
|
||||
<spring-boot.version>1.5.2.RELEASE</spring-boot.version>
|
||||
<mockito.version>1.10.19</mockito.version>
|
||||
<assertj.version>3.12.2</assertj.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,10 @@
|
|||
package com.baeldung.methodinjections;
|
||||
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan(basePackages = "com.baeldung.methodinjections")
|
||||
|
||||
public class AppConfig {
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.baeldung.methodinjections;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class Grader {
|
||||
|
||||
public String grade(Collection<Integer> marks) {
|
||||
|
||||
boolean result = marks.stream()
|
||||
.anyMatch(mark -> mark < 45);
|
||||
if (result) {
|
||||
return "FAIL";
|
||||
}
|
||||
return "PASS";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package com.baeldung.methodinjections;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("schoolNotification")
|
||||
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class SchoolNotification {
|
||||
@Autowired
|
||||
Grader grader;
|
||||
|
||||
private String name;
|
||||
private Collection<Integer> marks;
|
||||
|
||||
public SchoolNotification(String name) {
|
||||
this.name = name;
|
||||
this.marks = new ArrayList<Integer>();
|
||||
}
|
||||
|
||||
public String addMark(Integer mark) {
|
||||
this.marks.add(mark);
|
||||
return this.grader.grade(this.marks);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Collection<Integer> getMarks() {
|
||||
return marks;
|
||||
}
|
||||
|
||||
public void setMarks(Collection<Integer> marks) {
|
||||
this.marks = marks;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.baeldung.methodinjections;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Lookup;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("studentBean")
|
||||
public class Student {
|
||||
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* Injects a prototype bean SchoolNotification into Singleton student
|
||||
*/
|
||||
@Lookup
|
||||
public SchoolNotification getNotification(String name) {
|
||||
// spring overrides and returns a SchoolNotification instance
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package com.baeldung.methodinjections;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Lookup;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("studentService")
|
||||
public abstract class StudentServices {
|
||||
|
||||
private Map<String, SchoolNotification> notes = new HashMap<>();
|
||||
|
||||
@Lookup
|
||||
protected abstract SchoolNotification getNotification(String name);
|
||||
|
||||
public String appendMark(String name, Integer mark) {
|
||||
SchoolNotification notification = notes.computeIfAbsent(name, exists -> getNotification(name));
|
||||
return notification.addMark(mark);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.sample;
|
||||
package com.baeldung.sample;
|
||||
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.sample;
|
||||
package com.baeldung.sample;
|
||||
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
|
@ -0,0 +1,5 @@
|
|||
package com.baeldung.sample;
|
||||
|
||||
public class Bar {
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.sample;
|
||||
package com.baeldung.sample;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package com.baeldung.sample;
|
||||
|
||||
public class Foo {
|
||||
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package com.baeldung.sample;
|
||||
|
||||
public class FooDAO {
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.sample;
|
||||
package com.baeldung.sample;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.sample;
|
||||
package com.baeldung.sample;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.sample;
|
||||
package com.baeldung.sample;
|
||||
|
||||
public interface Formatter {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.sample;
|
||||
package com.baeldung.sample;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
package org.baeldung.sample;
|
||||
|
||||
public class Bar {
|
||||
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
package org.baeldung.sample;
|
||||
|
||||
public class Foo {
|
||||
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
package org.baeldung.sample;
|
||||
|
||||
public class FooDAO {
|
||||
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
spring.profiles.active=prod
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
|
||||
|
||||
<bean id="toyota" class="com.baeldung.constructordi.domain.Car">
|
||||
<constructor-arg index="0" ref="engine"/>
|
||||
<constructor-arg index="1" ref="transmission"/>
|
||||
</bean>
|
||||
|
||||
<bean id="engine" class="com.baeldung.constructordi.domain.Engine">
|
||||
<constructor-arg index="0" value="v4"/>
|
||||
<constructor-arg index="1" value="2"/>
|
||||
</bean>
|
||||
|
||||
<bean id="transmission" class="com.baeldung.constructordi.domain.Transmission">
|
||||
<constructor-arg value="sliding"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,22 @@
|
|||
<?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">
|
||||
|
||||
<bean id="exampleDAO" class="com.baeldung.beaninjection.ExampleDAOBean">
|
||||
<constructor-arg index="0" type="java.lang.String"
|
||||
value="Mandatory DAO Property X" />
|
||||
</bean>
|
||||
|
||||
<bean id="anotherSampleDAO" class="com.baeldung.beaninjection.AnotherSampleDAOBean">
|
||||
<constructor-arg index="0" type="java.lang.String"
|
||||
value="Mandatory DAO Property Y" />
|
||||
</bean>
|
||||
|
||||
<bean id="exampleService" class="com.baeldung.beaninjection.ExampleServiceBean">
|
||||
<constructor-arg index="0" ref="exampleDAO" />
|
||||
<property name="propertyX" value="Some Service Property X"></property>
|
||||
<property name="anotherSampleDAO" ref="anotherSampleDAO"></property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
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:component-scan base-package="com.baeldung.methodinjections" />
|
||||
|
||||
<bean id="schoolNotification" class="com.baeldung.methodinjections.SchoolNotification" scope="prototype"/>
|
||||
|
||||
<bean id="studentServices" class="com.baeldung.methodinjections.StudentServices" scope="prototype" >
|
||||
<lookup-method name="getNotification" bean="schoolNotification"/>
|
||||
</bean>
|
||||
</beans>
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue