PostgreSQL hibernate and spring - spring

I'm trying to use Hibernate with Spring and PostgreSQL, but I have lots of errors like:
org.postgresql.Driver : Connection error
ERROR 3424 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.
I have put postgreSQL.Driver in my libs but nothing to do error say there.
Edit:
2018-03-19 15:54:53.660 INFO 7640 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2018-03-19 15:54:54.664 WARN 7640 --- [ main] unknown.jul.logger : ConnectException occurred while connecting to localhost:5432`
`at com.ttmik.back.MainKt.main(main.kt:19) ~[classes/:na]
2018-03-19 15:54:54.675 ERROR 7640 --- [ main] org.postgresql.Driver : Connection error:
org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.

Check if your PostgreSQL can be reached by using telnet. If you get something like:
telnet localhost 5432
Connecting To localhost...
Could not open connection to the host, on port 5432: Connection failed
then most likely need to change listen_addresses to * in postgresql.conf file as per this answer on serverfault.

Related

How to connect docker db from dockerized spring boot app?

I am beginner on docker stuff and try to learn but I am stuck so hard.
When I only run db from docker-compose.yml and run the spring app called dockerdeneme directly from IDE then it connects to db, no problem. But when I try to run both from docker-compose.yml file then the app cannot connect to db. My docker-compose.yml file is:
version: '3.9'
services:
mysql:
platform: linux/amd64
image: mysql:8
container_name: mysqlcustomerdb
domainname: nishcustomer
hostname: localhost
ports:
- '3306:3306'
volumes:
- ~/apps/mysql:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=1234
- MYSQL_PASSWORD=1234
- MYSQL_DATABASE=mysqlcustomerdb
- DATABASE_HOST=mysqlcustomerdb
- MYSQL_ROOT_HOST=%
- lower_case_table_names=1
- init-connect='GRANT CREATE USER ON . TO 'root'#'%';FLUSH PRIVILEGES;'
dockerdeneme:
container_name: dockerdeneme
domainname: nishcustomer
hostname: localhost
image: dockerdeneme
build: ./
ports:
- '8080:8080'
environment:
- MYSQL_ROOT_PASSWORD=1234
- MYSQL_PASSWORD=1234
- MYSQL_USER=root
- MYSQL_DATABASE=mysqlcustomerdb
depends_on:
- mysql
volumes:
cache:
driver: local
Result of docker ps is:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fb0037e10702 mysql:8 "docker-entrypoint.s…" 22 seconds ago Up 21 seconds 0.0.0.0:3306->3306/tcp, 33060/tcp mysqlcustomerdb
If I run the application from IDE with following application.properties then it is working good:
spring.datasource.url=jdbc:mysql://localhost:3306/mysqlcustomerdb
spring.datasource.username=root
spring.datasource.password=1234
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
And it is the output of failing dockerized app:
2022-04-14 21:28:56.106 INFO 1 --- [ main] c.e.d.DockerdenemeApplication : Starting DockerdenemeApplication v0.0.1-SNAPSHOT using Java 11.0.14.1 on localhost with PID 1 (/app.jar started by root in /)
2022-04-14 21:28:56.107 INFO 1 --- [ main] c.e.d.DockerdenemeApplication : No active profile set, falling back to 1 default profile: "default"
2022-04-14 21:28:56.467 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-04-14 21:28:56.493 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 21 ms. Found 1 JPA repository interfaces.
2022-04-14 21:28:57.024 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-04-14 21:28:57.037 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-04-14 21:28:57.037 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.60]
2022-04-14 21:28:57.105 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-04-14 21:28:57.105 INFO 1 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 937 ms
2022-04-14 21:28:57.250 INFO 1 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2022-04-14 21:28:57.256 WARN 1 --- [ main] com.zaxxer.hikari.util.DriverDataSource : Registered driver with driverClassName=com.mysql.jdbc.Driver was not found, trying direct instantiation.
2022-04-14 21:28:58.334 ERROR 1 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174) ~[mysql-connector-java-8.0.28.jar!/:8.0.28]
I think I am doing something wrong with port mapping or hostname/domain name but I am stuck.
Can someone show me what am I doing wrong, ports or hostname etc?
localhost don't work for docker-compose apps. As a summary, use the ip of the host or a well configured docker network. Check:
https://stackoverflow.com/a/52213178/3957754
Pay special attention to : extra_hosts:
How to connect API with Web SPA through docker
Here you have a similar docker-compose with mysql and wordpress:
https://github.com/usil/wordpress-docker/blob/master/docker-compose.yml

Running Spring project causes warnings "RMI TCP Accept-0: accept loop for ServerSocket[addr=0.0.0.0/0.0.0.0,localport=54571] throws"

When I'am running start project from spring initializr I've this warning message
2021-06-03 15:48:38.987 WARN 9168 --- [MI TCP Accept-0] sun.rmi.transport.tcp : RMI TCP Accept-0: accept loop for ServerSocket[addr=0.0.0.0/0.0.0.0,localport=54408] throws
java.io.IOException: The server sockets created using the LocalRMIServerSocketFactory only accept connections from clients running on the host where the RMI remote objects have been exported.
at sun.management.jmxremote.LocalRMIServerSocketFactory$1.accept(LocalRMIServerSocketFactory.java:114) ~[na:1.8.0_291]
at sun.rmi.transport.tcp.TCPTransport$AcceptLoop.executeAcceptLoop(TCPTransport.java:405) [na:1.8.0_291]
at sun.rmi.transport.tcp.TCPTransport$AcceptLoop.run(TCPTransport.java:377) [na:1.8.0_291]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_291]
2021-06-03 15:48:39.081 INFO 9168 --- [ main] r.p.mmsclient.MmsclientApplication : Starting MmsclientApplication using Java 1.8.0_291 on d102 with PID 9168 (C:\Users\NTI\Downloads\mms-client\target\classes started by NTI in C:\Users\NTI\Downloads\mms-client)
2021-06-03 15:48:39.082 INFO 9168 --- [ main] r.p.mmsclient.MmsclientApplication : No active profile set, falling back to default profiles: default
2021-06-03 15:48:39.314 WARN 9168 --- [MI TCP Accept-0] sun.rmi.transport.tcp : RMI TCP Accept-0: accept loop for ServerSocket[addr=0.0.0.0/0.0.0.0,localport=54408] throws
java.io.IOException: The server sockets created using the LocalRMIServerSocketFactory only accept connections from clients running on the host where the RMI remote objects have been exported.
at sun.management.jmxremote.LocalRMIServerSocketFactory$1.accept(LocalRMIServerSocketFactory.java:114) ~[na:1.8.0_291]
at sun.rmi.transport.tcp.TCPTransport$AcceptLoop.executeAcceptLoop(TCPTransport.java:405) [na:1.8.0_291]
at sun.rmi.transport.tcp.TCPTransport$AcceptLoop.run(TCPTransport.java:377) [na:1.8.0_291]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_291]
2021-06-03 15:48:39.986 INFO 9168 --- [ main] r.p.mmsclient.MmsclientApplication : Started MmsclientApplication in 1.556 seconds (JVM running for 2.575)
Process finished with exit code 0
I believe that this is related to the local JMX agent and the configuration of the hosts file. First, ensure your hosts file has an appropriate mapping of localhost to 127.0.0.1. Then, add the following VM option:
-Djava.rmi.server.hostname=localhost
If you are using IntelliJ, you can find instructions for adding this VM option here.

No matter which port I use in my Spring Boot project, it shows up every time that Web server failed to start. Port #### was already in use

**When I hit my API endpoints it redirects to the spring default login page although I didn't use any spring security ** How can I solve this problem. And also no matter which port I used always failed to run showing the avobe error.
2021-03-18 22:20:28.987 INFO 1136 --- [ restartedMain] .s.s.UserDetailsServiceAutoConfiguration :
Using generated security password: 10ca6485-f9b1-45fd-8422-7f521974e807
2021-03-18 22:20:29.058 INFO 1136 --- [ restartedMain] o.s.s.web.DefaultSecurityFilterChain : Will secure any request with [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter#5afcaa40, org.springframework.security.web.context.SecurityContextPersistenceFilter#1ecd6c38, org.springframework.security.web.header.HeaderWriterFilter#57c0b97a, org.springframework.security.web.csrf.CsrfFilter#70e744e9, org.springframework.security.web.authentication.logout.LogoutFilter#ddc05c8, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#72ab48fb, org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter#77c3d4dd, org.springframework.security.web.authentication.ui.DefaultLogoutPageGeneratingFilter#53c95e38, org.springframework.security.web.authentication.www.BasicAuthenticationFilter#456f30b5, org.springframework.security.web.savedrequest.RequestCacheAwareFilter#723b9c48, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter#217298a9, org.springframework.security.web.authentication.AnonymousAuthenticationFilter#6f9f366c, org.springframework.security.web.session.SessionManagementFilter#3487264d, org.springframework.security.web.access.ExceptionTranslationFilter#bba9566, org.springframework.security.web.access.intercept.FilterSecurityInterceptor#2c1e9611]
2021-03-18 22:20:30.156 INFO 1136 --- [ restartedMain] o.s.cloud.commons.util.InetUtils
2021-03-18 22:20:30.366 INFO 1136 --- [ restartedMain] com.netflix.discovery.DiscoveryClient : Getting all instance registry info from the eureka server
2021-03-18 22:20:31.473 INFO 1136 --- [ restartedMain] c.n.d.s.t.d.RedirectingEurekaHttpClient : Request execution error. endpoint=DefaultEndpoint{ serviceUrl='http://localhost:8761/eureka/}, exception=I/O error on GET request for "http://localhost:8761/eureka/apps/": Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect stacktrace=org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://localhost:8761/eureka/apps/": Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:785)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:711)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:602)
at org.springframework.cloud.netflix.eureka.http.RestTemplateEurekaHttpClient.getApplicationsInternal(RestTemplateEurekaHttpClient.java:145)
at org.springframework.cloud.netflix.eureka.http.RestTemplateEurekaHttpClient.getApplications(RestTemplateEurekaHttpClient.java:135)
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$6.execute(EurekaHttpClientDecorator.java:137)
at com.netflix.discovery.shared.transport.decorator.RedirectingEurekaHttpClient.executeOnNewServer(RedirectingEurekaHttpClient.java:121)
at com.productservice.ProductServiceApplication.main(ProductServiceApplication.java:12)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: java.net.ConnectException: Connection refused: connect
at java.base/sun.nio.ch.Net.connect0(Native Method)
at java.base/sun.nio.ch.Net.connect(Net.java:574)
2021-03-18 22:20:31.473 WARN 1136 --- [ restartedMain] c.n.d.s.t.d.RetryableEurekaHttpClient : Request execution failed with message: I/O error on GET request for "http://localhost:8761/eureka/apps/": Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect
2021-03-18 22:20:31.474 INFO 1136 --- [ restartedMain] com.netflix.discovery.DiscoveryClient : DiscoveryClient_PRODUCT-SERVICE/localhost:product-service:8888 - was unable to refresh its cache! This periodic background refresh will be retried in 30 seconds. status = Cannot execute request on any known server stacktrace = com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:112)
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.getApplications(EurekaHttpClientDecorator.java:134)
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$6.execute(EurekaHttpClientDecorator.java:137)
at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:77)
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.getApplications(EurekaHttpClientDecorator.java:134)
at com.netflix.discovery.DiscoveryClient.getAndStoreFullRegistry(DiscoveryClient.java:1101)
at java.base/java.lang.Thread.run(Thread.java:832) ~[na:na]
2021-03-18 22:20:32.556 INFO 1136 --- [ restartedMain] com.netflix.discovery.DiscoveryClient : Unregistering ...
2021-03-18 22:20:33.561 INFO 1136 --- [ restartedMain] c.n.d.s.t.d.RedirectingEurekaHttpClient : Request execution error. endpoint=DefaultEndpoint{ serviceUrl='http://localhost:8761/eureka/}, exception=I/O error on DELETE request for "http://localhost:8761/eureka/apps/PRODUCT-SERVICE/localhost:product-service:8888": Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect stacktrace=org.springframework.web.client.ResourceAccessException: I/O error on DELETE request for "http://localhost:8761/eureka/apps/PRODUCT-SERVICE/localhost:product-service:8888": Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:785)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:711)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:602)
at org.springframework.cloud.netflix.eureka.http.RestTemplateEurekaHttpClient.cancel(RestTemplateEurekaHttpClient.java:87)
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$2.execute(EurekaHttpClientDecorator.java:74)
at com.netflix.discovery.shared.transport.decorator.RedirectingEurekaHttpClient.executeOnNewServer(RedirectingEurekaHttpClient.java:121)
at com.netflix.discovery.shared.transport.decorator.RedirectingEurekaHttpClient.execute(RedirectingEurekaHttpClient.java:80)
at com.netflix.discovery.sh
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-03-18 22:20:33.651 ERROR 1136 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Web server failed to start. Port 8888 was already in use.
Action:
Identify and stop the process that's listening on port 8888 or configure this application to listen on another port.
Process finished with exit code 0
**When I hit my API endpoints it redirects to the spring default login page although I didn't use any spring security ** How can I solve this problem. And also no matter which port I used always failed to run showing the avobe error.

Springboot Hikari Oracle RAC jdbc connection error

I'm getting error when deployingg project
INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Starting...
WARN o.s.b.a.j.DataSourceHealthIndicator - DataSource health check failed
java.lang.RuntimeException: Driver oracle.jdbc.OracleDriver claims to not accept jdbcUrl, jdbc-url:...
Connection String
jdbc:oracle:thin:
#(DESCRIPTION=(CONNECT_TIMEOUT=5)(TRANSPORT_CONNECT_TIMEOUT=3)(RETRY_COUNT=1)(ADDRESS=(PROTOCOL=TCP)(HOST=my2.org)(PORT=123))(ADDRESS=(PROTOCOL=TCP)(HOST=my1.org)(PORT=123))(CONNECT_DATA=(SERVICE_NAME=DG)))

Docker, Mongodb,Spring Boot on Windows getting Connection refused error

I am using default docker image of MongoDB and trying to connect using simple spring Boot application on windows box.
mongoDB image is getting stared correctly
IP in mongoDB image
I have spring-boot-starter-data-mongodb in my class path. i am using all spring boot default and only using below property in application.properties.
spring.data.mongodb.host=192.168.99.100
On application startup getting Connection refused: connect error
Logs
019-03-06 06:15:06.096 INFO 4664 --- [ main] org.mongodb.driver.cluster : Cluster created with settings {hosts=[192.168.99.100:27017], mode=MULTIPLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
2019-03-06 06:15:06.096 INFO 4664 --- [ main] org.mongodb.driver.cluster : Adding discovered server 192.168.99.100:27017 to client view of cluster
2019-03-06 06:15:06.356 WARN 4664 --- [ main] o.s.d.m.c.m.BasicMongoPersistentProperty : Customizing field name for id property not allowed! Custom name will not be considered!
2019-03-06 06:15:06.928 INFO 4664 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-03-06 06:15:07.164 INFO 4664 --- [68.99.100:27017] org.mongodb.driver.cluster : Exception in monitor thread while connecting to server 192.168.99.100:27017
What i am missing here ?
Not a MongoDB expert, but a moderate Docker user speaking: It looks like you are not publishing the port MongoDB runs by default: 27017. That's why your spring application could not get a connection and throws this exception:
Exception in monitor thread while connecting to server 192.168.99.100:27017
So you may try publishing the port by using -p 27017:27017when initiating mongo container.

Resources