Merge branch 'eugenp:master' into master
This commit is contained in:
+35
@@ -0,0 +1,35 @@
|
||||
package com.baeldung.removewhitespace;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class RemoveWhitespaceUnitTest {
|
||||
private final String myString = " I am a wonderful String ! ";
|
||||
|
||||
@Test
|
||||
void givenStringWithWhitespace_whenRemoveAllWhitespace_shouldGetExpectedResult() {
|
||||
String result = myString.replaceAll("\\s", "");
|
||||
assertThat(result).isEqualTo("IamawonderfulString!");
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenStringWithWhitespace_whenRemoveAllWhitespaceUsingStringUtils_shouldGetExpectedResult() {
|
||||
String result = StringUtils.deleteWhitespace(myString);
|
||||
assertThat(result).isEqualTo("IamawonderfulString!");
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenStringWithWhitespace_whenReplaceConsecutiveSpacesWithSingleSpace_shouldGetExpectedResult() {
|
||||
String result = myString.replaceAll("\\s+", " ");
|
||||
assertThat(result).isEqualTo(" I am a wonderful String ! ");
|
||||
assertThat(result.trim()).isEqualTo("I am a wonderful String !");
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenStringWithWhitespace_whenNormalizeWithApacheCommons_shouldGetExpectedResult() {
|
||||
String result = StringUtils.normalizeSpace(myString);
|
||||
assertThat(result).isEqualTo("I am a wonderful String !");
|
||||
}
|
||||
}
|
||||
@@ -2,4 +2,6 @@
|
||||
|
||||
- [Introduction to Docker Compose](https://www.baeldung.com/ops/docker-compose)
|
||||
- [How to Get Docker-Compose to Always Use the Latest Image](https://www.baeldung.com/ops/docker-compose-latest-image)
|
||||
- [Communication Between Multiple Docker Compose Projects](https://www.baeldung.com/ops/docker-compose-communication)
|
||||
- [Difference Between links and depends_on in Docker Compose](https://www.baeldung.com/ops/docker-compose-links-depends-on)
|
||||
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
services:
|
||||
my_app:
|
||||
image: web-app:latest
|
||||
container_name: web-app
|
||||
ports:
|
||||
- "8080:8080"
|
||||
networks:
|
||||
- my-app
|
||||
|
||||
networks:
|
||||
my-app:
|
||||
name: redis_network
|
||||
external: true
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
services:
|
||||
redis:
|
||||
image: redis:latest
|
||||
container_name: redis
|
||||
ports:
|
||||
- '6379:6379'
|
||||
networks:
|
||||
- network
|
||||
|
||||
networks:
|
||||
network:
|
||||
driver: bridge
|
||||
name: redis_network
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
services:
|
||||
my_app:
|
||||
image: web-app:latest
|
||||
container_name: web-app
|
||||
ports:
|
||||
- "8080:8080"
|
||||
networks:
|
||||
- network-example
|
||||
|
||||
networks:
|
||||
network-example:
|
||||
external: true
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
services:
|
||||
redis:
|
||||
image: redis:latest
|
||||
container_name: redis
|
||||
ports:
|
||||
- '6379:6379'
|
||||
networks:
|
||||
- network-example
|
||||
|
||||
networks:
|
||||
network-example:
|
||||
external: true
|
||||
@@ -13,3 +13,4 @@ This module contains articles about Bean Validation.
|
||||
- [Guide to ParameterMessageInterpolator](https://www.baeldung.com/hibernate-parametermessageinterpolator)
|
||||
- [Hibernate Validator Annotation Processor in Depth](https://www.baeldung.com/hibernate-validator-annotation-processor)
|
||||
- [Constraint Composition with Bean Validation](https://www.baeldung.com/java-bean-validation-constraint-composition)
|
||||
- [Using @NotNull on a Method Parameter](https://www.baeldung.com/java-notnull-method-parameter)
|
||||
|
||||
@@ -6,6 +6,10 @@
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<logger name="org.xacml4j.v30.XacmlPolicyTestSupport" level="warn">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</logger>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>maven-repository-download</artifactId>
|
||||
<name>Maven Release Repository</name>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>maven-repositories</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>nexus-snapshot</id>
|
||||
<name>nexus-snapshot</name>
|
||||
<url>http://localhost:8081/repository/maven-snapshots/</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>nexus-release</id>
|
||||
<name>nexus-release</name>
|
||||
<url>http://localhost:8081/repository/maven-releases/</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>maven-release-repository</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>maven-snapshot-repository</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>maven-release-repository</artifactId>
|
||||
<name>Maven Release Repository</name>
|
||||
<version>1.0.0</version>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>maven-repositories</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>nexus</id>
|
||||
<name>nexus-release</name>
|
||||
<url>http://localhost:8081/repository/maven-releases/</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>nexus</id>
|
||||
<name>nexus-release</name>
|
||||
<url>http://localhost:8081/repository/maven-releases/</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>maven-snapshot-repository</artifactId>
|
||||
<name>Maven Snapshot Repository</name>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>maven-repositories</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>nexus</id>
|
||||
<name>nexus-snapshot</name>
|
||||
<url>http://localhost:8081/repository/maven-snapshots/</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<distributionManagement>
|
||||
<snapshotRepository>
|
||||
<id>nexus</id>
|
||||
<name>nexus-snapshot</name>
|
||||
<url>http://localhost:8081/repository/maven-snapshots/</url>
|
||||
</snapshotRepository>
|
||||
</distributionManagement>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>maven-repositories</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<name>Maven Repositories</name>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>maven-modules</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
<module>maven-release-repository</module>
|
||||
<module>maven-snapshot-repository</module>
|
||||
<module>maven-download-artifacts</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
@@ -41,6 +41,7 @@
|
||||
<module>maven-parent-pom-resolution</module>
|
||||
<module>maven-simple</module>
|
||||
<module>maven-classifier</module>
|
||||
<module>maven-repositories</module>
|
||||
</modules>
|
||||
|
||||
<dependencyManagement>
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ import com.netflix.spectator.atlas.AtlasConfig;
|
||||
/**
|
||||
* @author aiet
|
||||
*/
|
||||
public class MicrometerAtlasIntegrationTest {
|
||||
public class MicrometerAtlasManualTest {
|
||||
|
||||
private AtlasConfig atlasConfig;
|
||||
|
||||
+2
-1
@@ -24,7 +24,8 @@ public class HibernateUtil {
|
||||
settings.put(Environment.USER, "sa");
|
||||
settings.put(Environment.PASS, "");
|
||||
settings.put(Environment.DIALECT, "org.hibernate.dialect.HSQLDialect");
|
||||
settings.put(Environment.SHOW_SQL, "true");
|
||||
// enable to show Hibernate generated SQL
|
||||
settings.put(Environment.SHOW_SQL, "false");
|
||||
settings.put(Environment.FORMAT_SQL, "true");
|
||||
settings.put(Environment.USE_SQL_COMMENTS, "true");
|
||||
settings.put(Environment.HBM2DDL_AUTO, "update");
|
||||
|
||||
+5
-2
@@ -2,11 +2,14 @@
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
|
||||
</pattern>
|
||||
<pattern>[%d{ISO8601}]-[%thread] %-5level %logger - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<logger name="org.hibernate" level="error">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</logger>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
### Relevant Artilces:
|
||||
- [Guide to Find in MongoDB](https://www.baeldung.com/mongodb-find)
|
||||
- [Query Documents using Document ID in MongoDB](https://www.baeldung.com/mongodb-query-documents-id)
|
||||
|
||||
@@ -4,4 +4,5 @@
|
||||
- [Configure MongoDB Collection Name for a Class in Spring Data](https://www.baeldung.com/spring-data-mongodb-collection-name)
|
||||
- [MongoDB Composite Key With Spring Data](https://www.baeldung.com/spring-data-mongodb-composite-key)
|
||||
- [Unique Field in MongoDB Document in Spring Data](https://www.baeldung.com/spring-data-mongodb-unique)
|
||||
- [Count Documents Using Spring Data MongoDB Repository](https://www.baeldung.com/spring-data-mongodb-count)
|
||||
- More articles: [[<--prev]](../spring-boot-persistence-mongodb)
|
||||
|
||||
@@ -6,6 +6,7 @@ This module contains articles about Spring Data REST
|
||||
- [Guide to Spring Data REST Validators](https://www.baeldung.com/spring-data-rest-validators)
|
||||
- [Spring Data Web Support](https://www.baeldung.com/spring-data-web-support)
|
||||
- [Spring REST and HAL Browser](https://www.baeldung.com/spring-rest-hal)
|
||||
- [Spring Data Rest – Serializing the Entity ID](https://www.baeldung.com/spring-data-rest-serialize-entity-id)
|
||||
|
||||
### The Course
|
||||
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||
|
||||
@@ -62,6 +62,16 @@
|
||||
<artifactId>spqr</artifactId>
|
||||
<version>0.11.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.reflections</groupId>
|
||||
<artifactId>reflections</artifactId>
|
||||
<version>0.10.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jboss</groupId>
|
||||
<artifactId>jandex</artifactId>
|
||||
<version>2.4.3.Final</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@@ -92,6 +102,27 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.jboss.jandex</groupId>
|
||||
<artifactId>jandex-maven-plugin</artifactId>
|
||||
<version>1.2.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>compile</phase>
|
||||
<id>make-index</id>
|
||||
<goals>
|
||||
<goal>jandex</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<fileSets>
|
||||
<fileSet>
|
||||
<directory>${project.build.outputDirectory}</directory>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.baeldung.annotation.scanner;
|
||||
|
||||
@SampleAnnotation(name = "SampleAnnotatedClass")
|
||||
public class SampleAnnotatedClass {
|
||||
|
||||
@SampleAnnotation(name = "annotatedMethod")
|
||||
public void annotatedMethod() {
|
||||
//Do something
|
||||
}
|
||||
|
||||
public void notAnnotatedMethod() {
|
||||
//Do something
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.baeldung.annotation.scanner;
|
||||
|
||||
import static java.lang.annotation.ElementType.METHOD;
|
||||
import static java.lang.annotation.ElementType.TYPE;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({ METHOD, TYPE })
|
||||
@Retention(RUNTIME)
|
||||
public @interface SampleAnnotation {
|
||||
String name();
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.baeldung.annotation.scanner;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SampleAnnotationScanner {
|
||||
List<String> scanAnnotatedMethods();
|
||||
|
||||
List<String> scanAnnotatedClasses();
|
||||
|
||||
boolean supportsMethodScan();
|
||||
|
||||
boolean supportsClassScan();
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package com.baeldung.annotation.scanner;
|
||||
|
||||
public class ScanNotSupportedException extends RuntimeException{
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package com.baeldung.annotation.scanner;
|
||||
|
||||
public class UnexpectedScanException extends RuntimeException {
|
||||
public UnexpectedScanException(Throwable ex) {
|
||||
super(ex);
|
||||
}
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
package com.baeldung.annotation.scanner.jandexlib;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.jboss.jandex.AnnotationInstance;
|
||||
import org.jboss.jandex.AnnotationTarget;
|
||||
import org.jboss.jandex.DotName;
|
||||
import org.jboss.jandex.Index;
|
||||
import org.jboss.jandex.IndexReader;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.baeldung.annotation.scanner.SampleAnnotationScanner;
|
||||
import com.baeldung.annotation.scanner.UnexpectedScanException;
|
||||
|
||||
@Service
|
||||
public class JandexScannerService implements SampleAnnotationScanner {
|
||||
@Value("classpath:META-INF/jandex.idx")
|
||||
private Resource appFile;
|
||||
|
||||
@Override
|
||||
public List<String> scanAnnotatedMethods() {
|
||||
try {
|
||||
final IndexReader reader = new IndexReader(appFile.getInputStream());
|
||||
Index jandexFile = reader.read();
|
||||
final List<AnnotationInstance> appAnnotationList = jandexFile.getAnnotations(DotName.createSimple("com.baeldung.annotation.scanner.SampleAnnotation"));
|
||||
List<String> annotatedMethods = new ArrayList<>();
|
||||
for (AnnotationInstance annotationInstance : appAnnotationList) {
|
||||
if (annotationInstance.target()
|
||||
.kind() == AnnotationTarget.Kind.METHOD) {
|
||||
annotatedMethods.add(annotationInstance.value("name")
|
||||
.value()
|
||||
.toString());
|
||||
}
|
||||
}
|
||||
return Collections.unmodifiableList(annotatedMethods);
|
||||
} catch (IOException e) {
|
||||
throw new UnexpectedScanException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> scanAnnotatedClasses() {
|
||||
try {
|
||||
final IndexReader reader = new IndexReader(appFile.getInputStream());
|
||||
Index jandexFile = reader.read();
|
||||
final List<AnnotationInstance> appAnnotationList = jandexFile.getAnnotations(DotName.createSimple("com.baeldung.annotation.scanner.SampleAnnotation"));
|
||||
List<String> annotatedClasses = new ArrayList<>();
|
||||
for (AnnotationInstance annotationInstance : appAnnotationList) {
|
||||
if (annotationInstance.target()
|
||||
.kind() == AnnotationTarget.Kind.CLASS) {
|
||||
annotatedClasses.add(annotationInstance.value("name")
|
||||
.value()
|
||||
.toString());
|
||||
}
|
||||
}
|
||||
return Collections.unmodifiableList(annotatedClasses);
|
||||
} catch (IOException e) {
|
||||
throw new UnexpectedScanException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsMethodScan() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsClassScan() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
package com.baeldung.annotation.scanner.javareflectionlib;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.baeldung.annotation.scanner.SampleAnnotation;
|
||||
import com.baeldung.annotation.scanner.SampleAnnotationScanner;
|
||||
import com.baeldung.annotation.scanner.UnexpectedScanException;
|
||||
|
||||
@Service
|
||||
public class JavaReflectionsScannerService implements SampleAnnotationScanner {
|
||||
@Override
|
||||
public List<String> scanAnnotatedMethods() {
|
||||
try {
|
||||
Class<?> clazz = ClassLoader.getSystemClassLoader()
|
||||
.loadClass("com.baeldung.annotation.scanner.SampleAnnotatedClass");
|
||||
Method[] methods = clazz.getMethods();
|
||||
List<String> annotatedMethods = new ArrayList<>();
|
||||
for (Method method : methods) {
|
||||
SampleAnnotation annotation = method.getAnnotation(SampleAnnotation.class);
|
||||
if (annotation != null) {
|
||||
annotatedMethods.add(annotation.name());
|
||||
}
|
||||
}
|
||||
return Collections.unmodifiableList(annotatedMethods);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new UnexpectedScanException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> scanAnnotatedClasses() {
|
||||
try {
|
||||
Class<?> clazz = ClassLoader.getSystemClassLoader()
|
||||
.loadClass("com.baeldung.annotation.scanner.SampleAnnotatedClass");
|
||||
SampleAnnotation classAnnotation = clazz.getAnnotation(SampleAnnotation.class);
|
||||
List<String> annotatedClasses = new ArrayList<>();
|
||||
annotatedClasses.add(classAnnotation.name());
|
||||
return Collections.unmodifiableList(annotatedClasses);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new UnexpectedScanException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsMethodScan() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsClassScan() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
package com.baeldung.annotation.scanner.reflectionslib;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.reflections.Reflections;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.baeldung.annotation.scanner.SampleAnnotation;
|
||||
import com.baeldung.annotation.scanner.SampleAnnotationScanner;
|
||||
|
||||
@Service
|
||||
public class ReflectionsScannerService implements SampleAnnotationScanner {
|
||||
@Override
|
||||
public List<String> scanAnnotatedMethods() {
|
||||
Reflections reflections = new Reflections("com.baeldung.annotation.scanner");
|
||||
Set<Method> methods = reflections.getMethodsAnnotatedWith(SampleAnnotation.class);
|
||||
return methods.stream()
|
||||
.map(method -> method.getAnnotation(SampleAnnotation.class)
|
||||
.name())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> scanAnnotatedClasses() {
|
||||
Reflections reflections = new Reflections("com.baeldung.annotation.scanner");
|
||||
Set<Class<?>> types = reflections.getTypesAnnotatedWith(SampleAnnotation.class);
|
||||
return types.stream()
|
||||
.map(clazz -> clazz.getAnnotation(SampleAnnotation.class)
|
||||
.name())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsMethodScan() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsClassScan() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
package com.baeldung.annotation.scanner.springcontextlib;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
|
||||
import org.springframework.core.type.filter.AnnotationTypeFilter;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.baeldung.annotation.scanner.SampleAnnotation;
|
||||
import com.baeldung.annotation.scanner.SampleAnnotationScanner;
|
||||
import com.baeldung.annotation.scanner.ScanNotSupportedException;
|
||||
|
||||
@Service
|
||||
public class SpringBeanAnnotationScannerService implements SampleAnnotationScanner {
|
||||
@Override
|
||||
public List<String> scanAnnotatedMethods() {
|
||||
throw new ScanNotSupportedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> scanAnnotatedClasses() {
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||
provider.addIncludeFilter(new AnnotationTypeFilter(SampleAnnotation.class));
|
||||
Set<BeanDefinition> beanDefs = provider.findCandidateComponents("com.baeldung.annotation.scanner");
|
||||
List<String> annotatedBeans = new ArrayList<>();
|
||||
for (BeanDefinition bd : beanDefs) {
|
||||
if (bd instanceof AnnotatedBeanDefinition) {
|
||||
Map<String, Object> annotAttributeMap = ((AnnotatedBeanDefinition) bd).getMetadata()
|
||||
.getAnnotationAttributes(SampleAnnotation.class.getCanonicalName());
|
||||
annotatedBeans.add(annotAttributeMap.get("name")
|
||||
.toString());
|
||||
}
|
||||
}
|
||||
return Collections.unmodifiableList(annotatedBeans);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsMethodScan() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsClassScan() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package com.baeldung.annotation.scanner.springcorelib;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
import com.baeldung.annotation.scanner.SampleAnnotationScanner;
|
||||
import com.baeldung.annotation.scanner.SampleAnnotatedClass;
|
||||
import com.baeldung.annotation.scanner.SampleAnnotation;
|
||||
import com.baeldung.annotation.scanner.ScanNotSupportedException;
|
||||
|
||||
@Service
|
||||
public class SpringCoreAnnotationScannerService implements SampleAnnotationScanner {
|
||||
@Override
|
||||
public List<String> scanAnnotatedMethods() {
|
||||
final Class<?> userClass = ClassUtils.getUserClass(SampleAnnotatedClass.class);
|
||||
return Arrays.stream(userClass.getMethods())
|
||||
.filter(method -> AnnotationUtils.getAnnotation(method, SampleAnnotation.class) != null)
|
||||
.map(method -> method.getAnnotation(SampleAnnotation.class)
|
||||
.name())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> scanAnnotatedClasses() {
|
||||
throw new ScanNotSupportedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsMethodScan() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsClassScan() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user