Spring + Firebird + REST。 パート1プロジェクトの構成

参加する代わりに


何かを分析している場合は、明確な言語で説明し、コメントを読んでコメントできる人を見つけてください(R.ファインマンと言い換えますが、はい、私はそうしました)。
すべてのコメントは、「はい、これは 〜白 ~~人 それ自体を「歓迎します。


目標


アプリケーション -製品の進捗レポート(スケール)の表示(可能であれば、企業内のネットワークを介したこれらのデータの配信(機能のため));
個人 -春の技術を少し理解している


技術



モチベーションガッシュスプリング+ファイアバード


最近、Ovsezavodオペレーター向けのLinux Mintの最初のクライアントプレースが作成され、Wineからのレポートの表示が常に適切であるとは限りませんでした。 (他のすべては正常に動作します-Qtの視覚化-SCADA、Java SEアーカイブ)。


踏まなければならない熊手


  1. 異なるバージョンのジャクソン依存関係(修正済み)、
  2. firebirdがエンコードタイプを設定しないと、デフォルト(S)なし、

出版物の最後にあるgitへのリンク。


ジャクソンとすべてすべて


さまざまなコンポーネントがさまざまなバージョンのジャクソンを締めました。これは不快なため、修正する必要があります。
チームによって明らかにされた


mvn dependency:tree -Dincludes=com.fasterxml.jackson.core +- org.springframework.boot:spring-boot-starter-web:jar:2.1.0.RELEASE:compile [INFO] | \- org.springframework.boot:spring-boot-starter-json:jar:2.1.0.RELEASE:compile [INFO] | \- com.fasterxml.jackson.core:jackson-databind:jar:2.9.7:compile [INFO] \- io.springfox:springfox-swagger2:jar:2.7.0:compile [INFO] \- io.swagger:swagger-models:jar:1.5.13:compile [INFO] \- com.fasterxml.jackson.core:jackson-annotations:jar:2.8.5:compile 

ポンポンで直します。


  <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.9.7</version> <exclusions> <exclusion> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> </exclusion> <exclusion> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-annotations</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> <version>2.9.7</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-annotations</artifactId> <version>2.9.7</version> </dependency> 

修正済み、約 判明した。 IDEAを使用している場合は、 外部ライブラリが見やすくなります。 すべての依存関係があり、適切なバージョンであること。


一般的なアプリケーション構造


アプリケーションのスプリングブートテストに慣れていないため、テストなしで実行します。
(「はい、その#肌の色はそれ自体を許可します」)


アプリケーション構成


私はベテランの開発者であり、確立された方法に精通していないため、次のことを行います。


  1. application.ymlで(データベース接続のセットアップ中)
     spring: datasource: driver-class-name: org.firebirdsql.jdbc.FBDriver url: jdbc:firebirdsql://host:3050//work/cmn/db/namedb.fdb?sql_dialect=3&charSet=utf-8 username: ****** password: ****** useUnicode: true characterEncoding: UTF-8 sql-script-encoding: UTF-8 jpa: show-sql: true 
  2. クラスでアノテーションを直接使用する:

charSet = utf-8を指定しない場合、デフォルトはNONEになります 。テーブルにもNONEがある場合、読み取り不可能な文字を取得するか、firebirdsql.orgによると:


 3.2.4 How can I solve the error “Connection rejected: No connection character set specified” If no character set has been set, Jaybird 3.0 will reject the connection with an SQLNonTransientConnectionException with message “Connection rejected: No connection character set specified (property lc_ctype, encoding, charSet or localEncoding). Please specify a connection character set (eg property charSet=utf-8) or consult the Jaybird documentation for more information.” 

クラスとファイルの最小セット


まず、index.htmlには空の本文が含まれています。
APIで実行しているのはSwaggerです。これは、プロジェクトの残りのパッケージと同じレベルに配置するパッケージ(インフラ)構成です。



プロジェクトに追加します。



RestController APIをあらゆる方法で使用します。これをSwaggerに示します。


 @Configuration @EnableSwagger2 public class SwaggerConfiguration { @Bean public Docket documentation(){ return new Docket(DocumentationType.SWAGGER_2) .select() .apis(RequestHandlerSelectors.withClassAnnotation(RestController.class)) .paths(PathSelectors.any()) .build(); } } 

Springアプリケーションを実行するクラスを作成します。


 @SpringBootApplication public class App { public static void main(String[] args) { SpringApplication.run(App.class,args); } } 

モデル、リポジトリ、リクエストが目的のテーブル用に作成されます(モジュールがあります):
今、あなたは@RestControllerを取ることができます


 @RestController @RequestMapping("/modules") @Api(tags = "Modules", description = "Modules API") public class CModulesResource { .... @GetMapping(value = "/{name}") @ApiOperation(value = "Find module",notes = "Find the module by Name") @ApiResponses(value = { @ApiResponse(code = 200,message = "Modules found"), @ApiResponse(code = 404,message = "Modules not found"), }) 

API-説明付きのクラスの名前。
説明付きの@ApiOperationメソッド名。
@ApiResponsesはAPIコードを返しました。
説明付きの@ApiResponse固有のコード。


例(はい、まだメインエンティティが含まれていますが、この記事では説明しません)


これで、REST APIを使用してデータの選択をテストできます。


使用された文献のリスト:


 1. https://www.baeldung.com 2. https://docs.spring.io 3. Spring in Action, 5th Edition 4. https://www.firebirdsql.org/file/documentation/drivers_documentation/java/faq.html#how-can-i-solve-the-error-connection-rejected-no-connection-character-set-specified 

githublink


Githubプロジェクト



Source: https://habr.com/ru/post/J432244/


All Articles