How to connect to Database with Spring Boot application.yml - spring

I have the PostgreSQL Database called db.
And here is my application.yml
spring:
jpa:
database: postgresql
show-sql: true
hibernate:
ddl-auto: create-drop
datasource:
schema: classpath:/schema.sql
platform: postgres
url: jdbc:postgresql://localhost:5432/db
username: postgres
password: postgres
driverClassName: org.postgresql.Driver
When I run my project, nothing happens, no errors and sure schema.sql that has a script for creating a table also does not work.
I have these dependencies in my pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
I don't understand why nothing happens even with no errors.
I hope for your help.

Related

Spring boot and JPA - javax.persistence.spi::No valid providers found

I am using Spring Boot for my application and try to access an MS SQL database through JPA.
But I am getting an error javax.persistence.spi::No valid providers found.
I added the necessary libs in dependencies:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<!--<version>2.4.13</version>-->
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
And I also used configuration in application.yaml
spring:
datasource:
url: jdbc:sqlserver://DEV\SQLLOKAL;databaseName=myDB
username: myDBUser
password: myDBPass
jpa:
properties:
hibernate:
dialect: org.hibernate.dialect.SQLServerDialect
hibernate:
ddl-auto: validate
show-sql: true
Is there any kind of more configuration missing? Or more dependencies?

SpringBoot JPA save in Impala

I develop a web service whit springboot and I need it save some info in my impala database.
I searching about save in impala and I only find how to use the JDBC.
Someone know if I can use spring boot and spring jpa to save data in impala?
My .yml
server:
port: 8080
spring:
config:
name: **
cloud:
loadbalancer:
ribbon:
enable: false
datasource:
url: jdbc:impala://...
username: ...
password: ...
driver-class-name: io.opentracing.contrib.jdbc.TracingDriver (I think this is not the correct but i find another)
My pom.xml
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>
<dependency>
<groupId>com.cloudera.impala.jdbc</groupId>
<artifactId>ImpalaJDBC41</artifactId>
<version>2.6.4.1005</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>es.caser.archit.spring</groupId>
<artifactId>db-caf-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>es.caser.archit.spring</groupId>
<artifactId>rest-caf-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>es.caser.archit.spring</groupId>
<artifactId>test-caf-boot-starter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>es.caser.archit.spring</groupId>
<artifactId>security-caf-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>2.1.0</version>
</dependency>
</dependencies>
Thanks :D
The driver class name should be
driverClassName: org.apache.hive.jdbc.HiveDriver
And use this dependency
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-jdbc</artifactId>
<version>3.1.2</version>
</dependency>

Spring Boot on Appengine standard doesn't start

I created a simple ( and almost empty ) spring boot project, I packaged into a jar and I deployed it on appengine.
But it doesn't start!
When I run https://.appspot.com I Have a 500 error page
I saw the database was created and the tables too, but there is something wrong into application
These are the last few lines of the log
Started VibesCoreApplication in 9.729 seconds (JVM running for 11.147)
Shutting down ExecutorService 'taskScheduler'
Closing JPA EntityManagerFactory for persistence unit 'default'
HikariPool-1 - Shutdown initiated...
HikariPool-1 - Shutdown completed.
this is a part of the pom file
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<!-- for GAE -->
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- for GAE -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-sqladmin</artifactId>
<version>v1beta4-rev76-1.25.0</version>
</dependency>
<dependency>
<groupId>com.google.cloud.sql</groupId>
<artifactId>mysql-socket-factory</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
<version>1.23.0</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-starter</artifactId>
<version>LATEST</version>
</dependency>
<!-- JPA -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>2.1.4.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-jdbc -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<version>2.2.2.RELEASE</version>
</dependency>
<!-- MySQL -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.17</version>
<scope>runtime</scope>
</dependency>
</dependencies>
this is the app.yaml file
runtime: java11
instance_class: F2
env: standard
network:
session_affinity: true
entrypoint: java -Xmx64m -jar target/vibes-core-0.4.0.jar
handlers:
- url: /(.*\.(gif|png|jpg|js|css|env))$
static_files: static/\1
upload: static/.*\.(gif|png|jpg)$
here there is the full logs
I was able to find a similar issue with yours here. The fact is that ( even this should not happen ) the configuration loading order may be broken.
In the post that I have sent you, the solution was removing the #EnableAutoConfiguration annotation.

How to configure connection pool in Spring Boot

How to configure my Spring Boot service to have max 2 open connections to the Postgres database? Application is used on the PRODUCTION only by a few people and I don't want to
my pom:
(...)
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.8.RELEASE</version>
<relativePath/>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-hibernate5</artifactId>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4-1200-jdbc41</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>slf4j-simple</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<dependency>
<groupId>com.caucho</groupId>
<artifactId>hessian</artifactId>
<version>4.0.51</version>
</dependency>
<dependency>
<groupId>com.vladmihalcea</groupId>
<artifactId>hibernate-types-52</artifactId>
<version>2.4.3</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
(...)
</build>
</project>
and my application.properties file:
spring.datasource.url=jdbc:postgresql://xxx
spring.datasource.username=xxx
spring.datasource.password=xxx
spring.datasource.maximum-pool-size=2 //I think it is not sufficient
info.app.name: xxx
I think spring.datasource.maximum-pool-size=2 is not sufficient. What should I add to the properties file? Should I maybe exclude HikariCP from my pom file?
Since Spring Boot 2.0, Hikari is the default DataSource implementation. Therefore, if you want to configure the maximumPoolSize (a parameter for Hikeri Configuration) in Spring Boot, you are supposed to set it as follows:
For application.properties
spring.datasource.hikari.maximum-pool-size=2
For application.yml
spring:
datasource:
hikari:
maximum-pool-size: 2
If you haven't changed the connection implementation pool that Spring is using, it should be HikariCP, and then the setting you're looking for is:
spring.datasource.hikari.maximum-pool-size
its listed here: https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-application-properties.html

Zipkin data not able to persist in Elastic search

I am having problem persisting the zipkin data. I did not get any error message. So I am sharing configuration to get a help.
I can see my logs in zipkin UI, but not able to persist in elastic search.
My zipkin-service pom file shared below.
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-autoconfigure-ui</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-zipkin-stream</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-binder-rabbit</artifactId>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-autoconfigure-storage-elasticsearch-http</artifactId>
<version>2.0.0</version>
</dependency>
<!-- add the dependency for elasticsearch via http -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
And my properties looks like this
spring:
profiles: local
rabbitmq:
host: ${RABBIT_HOST:localhost}
username: test
password: test
zipkin:
storage:
type: elasticsearch
elasticsearch:
jest:
uris: http://localhost:9200

Resources