BAEL-4068 Remove AspectJ DI from module spring-di

This commit is contained in:
Nguyen Nam Thai 2020-06-23 18:01:17 +07:00
parent 580a3bb920
commit fd16e9ed4f
6 changed files with 1 additions and 142 deletions

View File

@ -68,11 +68,6 @@
<artifactId>spring-boot-starter</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
@ -95,11 +90,7 @@
<artifactId>aspectjweaver</artifactId>
<version>${aspectjweaver.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- Spring -->
<!-- <dependency>-->
<!-- <groupId>org.springframework</groupId>-->
@ -138,27 +129,6 @@
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>${aspectj-plugin.version}</version>
<configuration>
<complianceLevel>${java.version}</complianceLevel>
<aspectLibraries>
<aspectLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</aspectLibrary>
</aspectLibraries>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
@ -194,7 +164,6 @@
<mockito.version>1.10.19</mockito.version>
<assertj.version>3.12.2</assertj.version>
<aspectjweaver.version>1.9.5</aspectjweaver.version>
<aspectj-plugin.version>1.11</aspectj-plugin.version>
</properties>
</project>

View File

@ -1,9 +0,0 @@
package com.baeldung.di.aspectj;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.aspectj.EnableSpringConfigured;
@ComponentScan
@EnableSpringConfigured
public class AspectJConfig {
}

View File

@ -1,12 +0,0 @@
package com.baeldung.di.aspectj;
import org.springframework.stereotype.Service;
@Service
public class IdService {
private static int count;
int generateId() {
return ++count;
}
}

View File

@ -1,36 +0,0 @@
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;
}
}

View File

@ -1,29 +0,0 @@
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;
}
}

View File

@ -1,24 +0,0 @@
package com.baeldung.di.aspectj;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import static org.junit.Assert.assertEquals;
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = AspectJConfig.class)
public class PersonUnitTest {
@Test
public void givenUnmanagedObjects_whenInjectingIdService_thenIdValueIsCorrectlySet() {
PersonObject personObject = new PersonObject("Baeldung");
personObject.generateId();
assertEquals(1, personObject.getId());
assertEquals("Baeldung", personObject.getName());
PersonEntity personEntity = new PersonEntity("Baeldung");
assertEquals(2, personEntity.getId());
assertEquals("Baeldung", personEntity.getName());
}
}