BAEL-4068 Add AspectJ DI to module spring-di-2

This commit is contained in:
Nguyen Nam Thai
2020-06-23 17:58:44 +07:00
parent 2c007f42bd
commit 580a3bb920
6 changed files with 175 additions and 0 deletions
@@ -0,0 +1,9 @@
package com.baeldung.di.aspectj;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.aspectj.EnableSpringConfigured;
@ComponentScan
@EnableSpringConfigured
public class AspectJConfig {
}
@@ -0,0 +1,12 @@
package com.baeldung.di.aspectj;
import org.springframework.stereotype.Service;
@Service
public class IdService {
private static int count;
int generateId() {
return ++count;
}
}
@@ -0,0 +1,36 @@
package com.baeldung.di.aspectj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Transient;
@Entity
@Configurable(preConstruction = true)
public class PersonEntity {
@Autowired
@Transient
private IdService idService;
@Id
private int id;
private String name;
public PersonEntity() {
}
public PersonEntity(String name) {
id = idService.generateId();
this.name = name;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
}
@@ -0,0 +1,29 @@
package com.baeldung.di.aspectj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
@Configurable
public class PersonObject {
@Autowired
private IdService idService;
private int id;
private String name;
public PersonObject(String name) {
this.name = name;
}
void generateId() {
this.id = idService.generateId();
}
public int getId() {
return id;
}
public String getName() {
return name;
}
}