Added tutorial sample for BAEL-2550
This commit is contained in:
parent
6a2dc09fb6
commit
29452abde4
|
@ -0,0 +1,38 @@
|
|||
package org.baeldung.sampleabstract;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
public abstract class AbstractGenericService<T, S> {
|
||||
|
||||
@Autowired
|
||||
private T genericFieldT;
|
||||
|
||||
private S genericFieldS;
|
||||
|
||||
public T getGenericFieldT() {
|
||||
|
||||
return genericFieldT;
|
||||
}
|
||||
|
||||
public void setGenericFieldT(T genericFieldT) {
|
||||
|
||||
this.genericFieldT = genericFieldT;
|
||||
}
|
||||
|
||||
public S getGenericFieldS() {
|
||||
|
||||
return genericFieldS;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setGenericFieldS(S genericFieldS) {
|
||||
|
||||
this.genericFieldS = genericFieldS;
|
||||
}
|
||||
|
||||
public void afterInitialize() {
|
||||
|
||||
System.out.println(genericFieldT.getClass().getSimpleName());
|
||||
System.out.println(genericFieldS.getClass().getSimpleName());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
package org.baeldung.sampleabstract;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
|
||||
public abstract class AbstractService {
|
||||
|
||||
@Autowired
|
||||
private FooBean fooBean;
|
||||
|
||||
private BarBean barBean;
|
||||
|
||||
private FooBarBean fooBarBean;
|
||||
|
||||
public AbstractService(FooBarBean fooBarBean) {
|
||||
|
||||
this.fooBarBean = fooBarBean;
|
||||
}
|
||||
|
||||
public FooBean getFooBean() {
|
||||
|
||||
return fooBean;
|
||||
}
|
||||
|
||||
public void setFooBean(FooBean fooBean) {
|
||||
|
||||
this.fooBean = fooBean;
|
||||
}
|
||||
|
||||
public BarBean getBarBean() {
|
||||
|
||||
return barBean;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setBarBean(BarBean barBean) {
|
||||
|
||||
this.barBean = barBean;
|
||||
}
|
||||
|
||||
public FooBarBean getFooBarBean() {
|
||||
|
||||
return fooBarBean;
|
||||
}
|
||||
|
||||
public void setFooBarBean(FooBarBean fooBarBean) {
|
||||
|
||||
this.fooBarBean = fooBarBean;
|
||||
}
|
||||
|
||||
public void afterInitialize() {
|
||||
|
||||
System.out.println(fooBean.value());
|
||||
System.out.println(barBean.value());
|
||||
System.out.println(fooBarBean.value());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package org.baeldung.sampleabstract;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class BarBean {
|
||||
|
||||
public String value() {
|
||||
|
||||
return "barBean";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package org.baeldung.sampleabstract;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan(basePackages = "org.baeldung.sampleabstract")
|
||||
public class DemoApp {
|
||||
|
||||
@Autowired
|
||||
private FooService fooService;
|
||||
|
||||
@Autowired
|
||||
private FooGenericService fooGenericService;
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
ApplicationContext applicationContext = new AnnotationConfigApplicationContext(DemoApp.class);
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void afterInitialize() {
|
||||
|
||||
fooService.afterInitialize();
|
||||
fooGenericService.afterInitialize();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package org.baeldung.sampleabstract;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class FooBarBean {
|
||||
|
||||
public String value() {
|
||||
|
||||
return "fooBarBean";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package org.baeldung.sampleabstract;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class FooBean {
|
||||
|
||||
public String value() {
|
||||
|
||||
return "fooBean";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package org.baeldung.sampleabstract;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class FooGenericService extends AbstractGenericService<FooBean, BarBean> {
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package org.baeldung.sampleabstract;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class FooService extends AbstractService {
|
||||
|
||||
@Autowired
|
||||
public FooService(FooBarBean fooBarBean) {
|
||||
|
||||
super(fooBarBean);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue