2

Spring Boot アプリケーションのカスタム エンドポイントを作成しようとしています。カスタム エンドポイントの実装を以下のように記述しました。コードのサイズを小さくするために、インポートなどの余分なものは含めていません。

@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;
    }

}

上記のコードを記述したら、アプリケーションを再起動し、/test からエンドポイントにアクセスしようとしました。ただし、エンドポイントは使用できません。以下は、Spring Boot 起動アプリケーションです。

@Configuration
@EnableAutoConfiguration
public class Application{

    public static void main(final String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

それとは別に、Spring Boot Actuator を実行するためのすべてが揃っています。/info、/metrics などのデフォルトのエンドポイントにアクセスできました。

ここで何か不足している場合は、知識を共有していただけますか。カスタム エンドポイント クラスは、開発者がそれ以上構成しなくても読み込まれると想定しています。

4

1 に答える 1

0

この問題は解決しました。まず、アプリケーション クラスに @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

これはパッケージによるものです。ルートパッケージからメインクラスを実行しようとしました。これがSpring Bootアプリケーションのバグかどうかはわかりません.JIRAをサイトに記録します. パッケージ構造のレベルをもう 1 つ追加すると、正常に動作し始めました。

于 2015-08-30T12:32:59.690 に答える