Remove spring-autowire (#1319)
This commit is contained in:
committed by
GitHub
parent
e1d136368b
commit
f07985b402
@@ -0,0 +1,11 @@
|
||||
package org.baeldung.sample;
|
||||
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
|
||||
public class App {
|
||||
public static void main(String[] args) {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(AppConfig.class);
|
||||
FooService fooService = ctx.getBean(FooService.class);
|
||||
fooService.doStuff();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package org.baeldung.sample;
|
||||
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan("com.baeldung.autowire.sample")
|
||||
public class AppConfig {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package org.baeldung.sample;
|
||||
|
||||
public class Bar {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.baeldung.sample;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@FormatterType("Bar")
|
||||
@Component
|
||||
public class BarFormatter implements Formatter {
|
||||
|
||||
public String format() {
|
||||
return "bar";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package org.baeldung.sample;
|
||||
|
||||
public class Foo {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package org.baeldung.sample;
|
||||
|
||||
public class FooDAO {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.baeldung.sample;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@FormatterType("Foo")
|
||||
@Component
|
||||
public class FooFormatter implements Formatter {
|
||||
|
||||
public String format() {
|
||||
return "foo";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.baeldung.sample;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class FooService {
|
||||
|
||||
@Autowired
|
||||
@FormatterType("Foo")
|
||||
private Formatter formatter;
|
||||
|
||||
public String doStuff() {
|
||||
return formatter.format();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package org.baeldung.sample;
|
||||
|
||||
public interface Formatter {
|
||||
|
||||
String format();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.baeldung.sample;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
|
||||
@Qualifier
|
||||
@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.TYPE, ElementType.PARAMETER })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface FormatterType {
|
||||
|
||||
String value();
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user