Spring boot 弹簧启动执行器中的自定义端点
我正在尝试为Spring Boot应用程序编写自定义端点。我已经编写了自定义端点实现,如下所示。我没有包括额外的东西,如导入,以减少代码的大小Spring boot 弹簧启动执行器中的自定义端点,spring-boot,spring-boot-actuator,Spring Boot,Spring Boot Actuator,我正在尝试为Spring Boot应用程序编写自定义端点。我已经编写了自定义端点实现,如下所示。我没有包括额外的东西,如导入,以减少代码的大小 @Component public class TestendPoint implements Endpoint<List<String>>{ public String getId() { return "test"; } public List<String>
@Component
public class TestendPoint implements Endpoint<List<String>>{
public String getId() {
return "test";
}
public List<String> invoke() {
List<String> test= new ArrayList<String>();
test.add("Details 1");
test.add("Details 2");
return serverDetails;
}
public boolean isEnabled() {
return true;
}
public boolean isSensitive() {
return false;
}
}
除此之外,我有一切运行弹簧启动驱动器。我可以访问默认端点,如/info、/metrics等
如果我遗漏了什么,你能分享一下你的知识吗。我假设自定义端点类将在没有开发人员进一步配置的情况下加载 我已经解决了这个问题。首先,我没有在应用程序类中包含@ComponentScan注释。或者我应该有@SpringBoot应用程序。添加注释时,我开始出现以下异常:
Caused by: java.lang.IllegalStateException: Could not evaluate condition owing to internal class not found. This can happen if you are @ComponentScanning a springframework package (e.g. if you put a @ComponentScan in the default package by mistake)
at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:50)
at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:92)
at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:79)
at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:62)
at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.isConditionMatch(ClassPathScanningCandidateComponentProvider.java:361)
at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.isCandidateComponent(ClassPathScanningCandidateComponentProvider.java:345)
at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:278)
... 18 more
Caused by: java.lang.NoClassDefFoundError: org/springframework/dao/DataAccessException
at org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$EmbeddedDatabaseCondition.getMatchOutcome(DataSourceAutoConfiguration.java:308)
at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:129)
at org.springframework.boot.autoconfigure.condition.SpringBootCondition.anyMatches(SpringBootCondition.java:112)
at org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$DatabaseCondition.getMatchOutcome(DataSourceAutoConfiguration.java:333)
at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:44)
... 24 more
这是由于包装问题。我已尝试从根包执行main类。我不确定这是否是spring boot应用程序中的一个bug,我会在他们的站点上记录一个JIRA。一旦我添加了一个更高级别的包结构,它就开始正常工作。我应该在spring boot应用程序类中包括@ComponentScan吗。如果我加上,我会得到例外不,这不是一个错误。当你把你的spring boot应用程序放在根包中时,你有一个fat警告日志,它应该让你知道一些东西可能会坏掉。请参阅,谢谢您的澄清。但我没有使用默认包来获取该异常。我使用根包进行组件扫描您的问题看起来正是我创建的新问题#3850
Caused by: java.lang.IllegalStateException: Could not evaluate condition owing to internal class not found. This can happen if you are @ComponentScanning a springframework package (e.g. if you put a @ComponentScan in the default package by mistake)
at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:50)
at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:92)
at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:79)
at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:62)
at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.isConditionMatch(ClassPathScanningCandidateComponentProvider.java:361)
at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.isCandidateComponent(ClassPathScanningCandidateComponentProvider.java:345)
at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:278)
... 18 more
Caused by: java.lang.NoClassDefFoundError: org/springframework/dao/DataAccessException
at org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$EmbeddedDatabaseCondition.getMatchOutcome(DataSourceAutoConfiguration.java:308)
at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:129)
at org.springframework.boot.autoconfigure.condition.SpringBootCondition.anyMatches(SpringBootCondition.java:112)
at org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$DatabaseCondition.getMatchOutcome(DataSourceAutoConfiguration.java:333)
at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:44)
... 24 more