私は「学習春ブーツ2.0 - 第二版:簡素化microservicesと反応性のプログラミングに基づいて雷の高速アプリケーションの開発」を読み始めましたし、最初のサンプルプログラムの一つとのトラブルを抱えています。
私は上のGETを行うとhttp://localhost:8080/chapters
、それを返します。
[
{},
{},
{}
]
の代わりに:
[
{"id": 1,
"name": "Quick Start with Java"},
{"id":,
"name": "Reactive Web with Spring Boot"},
{"id": 3,
"name": ... and more!"}
]
これは私のコード(マイナス輸入)です。
@Data
@Document
public class Chapter {
@Id
private String id;
private String name;
public Chapter(String name) {
this.name = name;
}
}
public interface ChapterRepository extends ReactiveCrudRepository<Chapter, String>{
}
@Configuration
public class LoadDatabase {
@Bean
CommandLineRunner init(ChapterRepository repository) {
return args -> {
Flux.just(
new Chapter("Quick Start with Java"),
new Chapter("Reactive Web with Spring Boot"),
new Chapter("... and more!"))
.flatMap(repository::save)
.subscribe(System.out::println);
};
}
}
@RestController
public class ChapterController {
private final ChapterRepository repository;
public ChapterController(ChapterRepository repository) {
this.repository = repository;
}
@GetMapping("/chapters")
public Flux<Chapter> listing() {
return repository.findAll();
}
}
私のコードに何か問題はありますか?
追加情報
以下のコメントで述べたように、私は開発のビットを持っていました。以前、私は私のIDEでこれを実行しようとしました。私は、プロジェクト、./gradlewクリーンビルドを構築するのGradle使用します。java -jarビルド/ libsに/学習スプリングブート-0.0.1-SNAPSHOT.jarにと私の端末から、それを実行し、私は適切な応答を取得します。不眠症、ポストマン、ブラウザやカールのための作品。これは私は私の仕事でcintinueすることができますが、私は、これは私のIDEのための解決を取得してみたいです。私は、Eclipse用の春のツールスイートを使用しています。
私が気づいたことの一つは、私はこれでコンソール出力が終了するSTSでサーバを起動するときということです。
2018-09-09 09:54:50.646 INFO 12073 --- [ntLoopGroup-2-3] org.mongodb.driver.connection : Opened connection [connectionId{localValue:4, serverValue:31}] to localhost:27017
2018-09-09 09:54:50.647 INFO 12073 --- [ntLoopGroup-2-2] org.mongodb.driver.connection : Opened connection [connectionId{localValue:3, serverValue:30}] to localhost:27017
2018-09-09 09:54:50.649 INFO 12073 --- [ntLoopGroup-2-4] org.mongodb.driver.connection : Opened connection [connectionId{localValue:5, serverValue:32}] to localhost:27017
com.greglturnquist.learningspringboot.learningspringboot.Chapter@c56c194
com.greglturnquist.learningspringboot.learningspringboot.Chapter@795759ac
com.greglturnquist.learningspringboot.learningspringboot.Chapter@76e125f2
ターミナルで実行したときに、私は本の名前を見ることができます:
2018-09-09 09:52:42.768 INFO 12058 --- [ntLoopGroup-2-2] org.mongodb.driver.connection : Opened connection [connectionId{localValue:3, serverValue:25}] to localhost:27017
2018-09-09 09:52:42.789 INFO 12058 --- [ntLoopGroup-2-3] org.mongodb.driver.connection : Opened connection [connectionId{localValue:4, serverValue:26}] to localhost:27017
2018-09-09 09:52:42.791 INFO 12058 --- [ntLoopGroup-2-4] org.mongodb.driver.connection : Opened connection [connectionId{localValue:5, serverValue:27}] to localhost:27017
Chapter(id=5b94df5ac0b4b02f1af43f43, name=Quick Start with Java)
Chapter(id=5b94df5ac0b4b02f1af43f44, name=Reactive Web with Spring Boot)
Chapter(id=5b94df5ac0b4b02f1af43f45, name=...and more!)
私は非常に同じ問題を持っていた、と私のために私は私のIDEは、ロンボクの注釈処理は、(私はIntelliJのUltimateを使用しています)が有効になっていたことを確認する必要がありました。これを可能にし、私のアプリを再起動すると、私は期待通りのデータを見て開始し、JSON配列を空にしません。