JAVA-86: Remove spring-boot-failure-analyzer

This commit is contained in:
Krzysiek 2020-03-21 16:13:59 +01:00
parent 4f8cb3cf37
commit 3f21f970b8
10 changed files with 0 additions and 152 deletions

View File

@ -12,7 +12,6 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
- [How to Register a Servlet in Java](https://www.baeldung.com/register-servlet) - [How to Register a Servlet in Java](https://www.baeldung.com/register-servlet)
- [Guide to Spring WebUtils and ServletRequestUtils](https://www.baeldung.com/spring-webutils-servletrequestutils) - [Guide to Spring WebUtils and ServletRequestUtils](https://www.baeldung.com/spring-webutils-servletrequestutils)
- [Guide to Internationalization in Spring Boot](https://www.baeldung.com/spring-boot-internationalization) - [Guide to Internationalization in Spring Boot](https://www.baeldung.com/spring-boot-internationalization)
- [Create a Custom FailureAnalyzer with Spring Boot](https://www.baeldung.com/spring-boot-failure-analyzer)
- [Dynamic DTO Validation Config Retrieved from the Database](https://www.baeldung.com/spring-dynamic-dto-validation) - [Dynamic DTO Validation Config Retrieved from the Database](https://www.baeldung.com/spring-dynamic-dto-validation)
- [Custom Information in Spring Boot Info Endpoint](https://www.baeldung.com/spring-boot-info-actuator-custom) - [Custom Information in Spring Boot Info Endpoint](https://www.baeldung.com/spring-boot-info-actuator-custom)
- [Testing in Spring Boot](https://www.baeldung.com/spring-boot-testing) - [Testing in Spring Boot](https://www.baeldung.com/spring-boot-testing)

View File

@ -1,14 +0,0 @@
package com.baeldung.failureanalyzer;
import javax.annotation.security.RolesAllowed;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class FailureAnalyzerApplication {
@RolesAllowed("*")
public static void main(String[] args) {
SpringApplication.run(FailureAnalyzerApplication.class, args);
}
}

View File

@ -1,22 +0,0 @@
package com.baeldung.failureanalyzer;
import org.springframework.beans.factory.BeanNotOfRequiredTypeException;
import org.springframework.boot.diagnostics.AbstractFailureAnalyzer;
import org.springframework.boot.diagnostics.FailureAnalysis;
public class MyBeanNotOfRequiredTypeFailureAnalyzer extends AbstractFailureAnalyzer<BeanNotOfRequiredTypeException> {
@Override
protected FailureAnalysis analyze(Throwable rootFailure, BeanNotOfRequiredTypeException cause) {
return new FailureAnalysis(getDescription(cause), getAction(cause), cause);
}
private String getDescription(BeanNotOfRequiredTypeException ex) {
return String.format("The bean %s could not be injected as %s because it is of type %s", ex.getBeanName(), ex.getRequiredType().getName(), ex.getActualType().getName());
}
private String getAction(BeanNotOfRequiredTypeException ex) {
return String.format("Consider creating a bean with name %s of type %s", ex.getBeanName(), ex.getRequiredType().getName());
}
}

View File

@ -1,5 +0,0 @@
package com.baeldung.failureanalyzer;
public class MyDAO {
}

View File

@ -1,8 +0,0 @@
package com.baeldung.failureanalyzer;
import org.springframework.stereotype.Repository;
@Repository("myDAO")
public class MySecondDAO {
}

View File

@ -1,13 +0,0 @@
package com.baeldung.failureanalyzer;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
@Service
public class MyService {
@Resource(name = "myDAO")
private MyDAO myDAO;
}

View File

@ -1,2 +0,0 @@
org.springframework.boot.diagnostics.FailureAnalyzer=com.baeldung.failureanalyzer.MyBeanNotOfRequiredTypeFailureAnalyzer

View File

@ -1,47 +0,0 @@
package com.baeldung.failureanalyzer;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Collection;
import java.util.stream.Collectors;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.boot.SpringApplication;
import com.baeldung.failureanalyzer.utils.ListAppender;
import ch.qos.logback.classic.spi.ILoggingEvent;
public class FailureAnalyzerAppIntegrationTest {
private static final String EXPECTED_ANALYSIS_DESCRIPTION_TITLE = "Description:";
private static final String EXPECTED_ANALYSIS_DESCRIPTION_CONTENT = "The bean myDAO could not be injected as com.baeldung.failureanalyzer.MyDAO because it is of type com.baeldung.failureanalyzer.MySecondDAO";
private static final String EXPECTED_ANALYSIS_ACTION_TITLE = "Action:";
private static final String EXPECTED_ANALYSIS_ACTION_CONTENT = "Consider creating a bean with name myDAO of type com.baeldung.failureanalyzer.MyDAO";
@BeforeEach
public void clearLogList() {
ListAppender.clearEventList();
}
@Test
public void givenBeanCreationErrorInContext_whenContextLoaded_thenFailureAnalyzerLogsReport() {
try {
SpringApplication.run(FailureAnalyzerApplication.class);
} catch (BeanCreationException e) {
Collection<String> allLoggedEntries = ListAppender.getEvents()
.stream()
.map(ILoggingEvent::getFormattedMessage)
.collect(Collectors.toList());
assertThat(allLoggedEntries).anyMatch(entry -> entry.contains(EXPECTED_ANALYSIS_DESCRIPTION_TITLE))
.anyMatch(entry -> entry.contains(EXPECTED_ANALYSIS_DESCRIPTION_CONTENT))
.anyMatch(entry -> entry.contains(EXPECTED_ANALYSIS_ACTION_TITLE))
.anyMatch(entry -> entry.contains(EXPECTED_ANALYSIS_ACTION_CONTENT));
return;
}
throw new IllegalStateException("Context load should be failing due to a BeanCreationException!");
}
}

View File

@ -1,25 +0,0 @@
package com.baeldung.failureanalyzer.utils;
import java.util.ArrayList;
import java.util.List;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.AppenderBase;
public class ListAppender extends AppenderBase<ILoggingEvent> {
static private List<ILoggingEvent> events = new ArrayList<>();
@Override
protected void append(ILoggingEvent eventObject) {
events.add(eventObject);
}
public static List<ILoggingEvent> getEvents() {
return events;
}
public static void clearEventList() {
events.clear();
}
}

View File

@ -1,15 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include
resource="org/springframework/boot/logging/logback/base.xml" />
<appender name="LISTAPPENDER"
class="com.baeldung.failureanalyzer.utils.ListAppender">
</appender>
<logger
name="org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter">
<appender-ref ref="LISTAPPENDER" />
</logger>
<root level="info">
<appender-ref ref="CONSOLE" />
</root>
</configuration>