📜 ⬆️ ⬇️

Spring + Firebird + REST. Part 1 Configuring the Project

Instead of intro


If you make out something, try to describe it in a clear language and find someone who reads and makes comments (paraphrased R. Feynman, and yes I did).
All comments, even vicious in the style of "Yes, that this ~ white ~~ people allows yourself "welcome.


Goals


Applications - display of reports on the progress of the product (scales), if possible, with the distribution of these data over the network within the enterprise (for functionality);
Personal - a little understanding of technology spring


Technology



Motivation to gash spring + firebird


Recently, the first client place under the Linux Mint OS was made for the operator “Ovzazavod” and not always the adequate work of displaying reports from under Wine. (everything else works with norms - Qt - SCADA visualization, Java SE archives).


Some rakes that had to come


  1. Jackson dependencies of different versions (corrected),
  2. firebird not set encoding type leads to default (Noah) NONE,

Link to git at the end of the post.


Jackson and everything all everything


Different components of jackson tightened different versions, as it is unpleasant, it is necessary to fix it.
Revealed command


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 

Fix in pom.


  <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> 

Corrected, ok. happened. If you use IDEA, then it is even easier to look at External Libraries . That all dependencies are there and they are the right versions.


General structure of the application


Spring Boot is not familiar with layering testing of Spring Boot, so I’ll do it without tests
("What this # color_skin allows itself").


Application configuration


Since I am a seasoned developer, which means I am not familiar with the well-established methods, I will do:


  1. in application.yml (while setting up a connection to the database)
     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. using annotations directly in classes:

If you do not specify charSet = utf-8, then the default will be NONE : In case the tables are also NONE, we get unreadable characters or, according to 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.” 

Minimum set of classes and files


To begin, index.html contains an empty body;
Running in API - Swagger, package (infra) configurations of which will be placed on the level with the rest of the project package.



I will add to the project:



We will work with RestController API on all paths, we will specify it 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(); } } 

Create a class that launches Spring Application:


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

Models, repositories, requests are created for the desired table (I have modules):
Now you can take on @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 - the name of the class with the description;
@ApiOperation method name with description;
@ApiResponses returned API codes;
@ApiResponse specific code with description;


Example (yes, it also has a main entity, which I don’t describe in the article)


Now you can test the sample data by REST API.


Bibliography:


 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 project


')

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


All Articles