JDBC Postgres in Spring Application - spring

New to spring. Trying to establish postgres connection in spring framework using Java. Eclipse is the editor tool.
Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [org.postgresql.Driver]
I have given the connector in build paths etc. Please help.
Not able to figure out what is the issue!

Related

Connection Timeout for Spring Redis using Redis Cloud

I am trying to connect Redis in my Spring application.
I have created a Redis Database in Redis Cloudredis-10228.c15.us-east-1-2.ec2.cloud.redislabs.com:10228.
I have configured the following in my application.properties
spring.redis.host=redis-10228.c15.us-east-1-2.ec2.cloud.redislabs.com:10228
spring.redis.password=<password-from-redis-cloud>
I am still getting Redis Connection failure event after providing password.
reactor.core.Exceptions$ErrorCallbackNotImplemented: org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to redis-10228.c15.us-east-1-2.ec2.cloud.redislabs.com:10228
Caused by: org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to redis-10228.c15.us-east-1-2.ec2.cloud.redislabs.com:10228
Any misconfiguration done from my part?
You need to specify the redis port in a different property:
spring.redis.host=redis-10228.c15.us-east-1-2.ec2.cloud.redislabs.com
spring.redis.port=10228
See this for more details.

Spring boot application restarts on its own when Elastic search is down

I have a spring boot application that is integrated with MySQL and Elastic Search. Most APIs connect directly with MySQL to fetch the data. Only 1 API fetch data from elastic search.
If Elastic Search goes down while the application is still running, the entire application tries to restart and fails since it is unable to connect with ES. When I checked the logs, I can see a lot of org.springframework.beans.factory.UnsatisfiedDependencyException error
#EnableElasticsearchRepositories declared on Application: Invocation
of init method failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate
[org.springframework.data.elasticsearch.repository.support.SimpleElasticsearchRepository]:
Constructor threw exception; nested exception is
org.springframework.data.elasticsearch.UncategorizedElasticsearchException:
method [HEAD],
This causes the remaining APIs to be unavailable as well although they don't need Elastic Search to work. Is there a way to make sure the application stills runs fine even when the Elastic search is down? I did prefer to have only one API unavailable instead of the whole application going down

Unable to acquire JDBC Connection in SpringBoot app

I have a Microservices‑Based Application, each Microservice is a SpringBoot 2.0.3.RELEASE app., but after my 4rth Microservices launched I have this error:
Unable to acquire JDBC Connection; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection
..
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Too many connections
I would like to know how to reduce the maximumPoolSize or if there is a way to know maximumPoolSize because I have't seen anything related when the app starts
You can set the maximum pool size of the JDBC connections in your application.properties file like:
spring.datasource.hikari.maximum-pool-size=5

Websphere Default Message Provider and Spring JMS

I am trying to consume messages from WebSphere SIB (default message provider). I did not find many articles related to this topic on the internet. I have tried configuration as described here but i get the below exception:
com.ibm.websphere.ms.Wnsinitalcontextfacotry is not of type javax.jms.ConnectionFactory
Has anybody integrated JMS with WebShphere Default message provider? If yes, can you please provide sample code?
I would like to know how to configure connection factory and topic.
CURRENT Status is Below:
I was able to configure JMS connection factory and topic but hit below exception
The security exception CAUGHT_EXCEPTION_WHILE_CONFIGURING_SSL_CLIENT_SOCKET: JSSL0130E: java.io.IOException: signals that an I/O exception of some sort has occurred.
Check this post. It provides steps and piece of plain Java code, how to access WebSphere Default messaging. You should be able to configure your Spring app based on that.

JSTL SQL setDataSource not working with Webshpere 8.5

<sql:setDataSource var="TCIT" scope="application"
driver="${driver}"
url="${url}"
user="${username}"
password="${password}" />
The above code is used in a legacy application deployed in OC4J that is being migrated to WebSphere 8.5. The properties in {} above are fetched from a property file. Ensured the values are coming correctly form there. However, when the database connection is created the application is encountering the following exception: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver" . I have the ojdbc14.jar in the WEB-INF/lib folder, still facing the issue.
Finally the issue got resolved creating a JDBC connection pool at Application server level. Turns out Websphere does not allow the connection to be created using the above method. Below is the modified tag that is using JNDI lookup for accessing the JDBC connection pool at application level.
<sql:setDataSource var="connPool" scope="application" dataSource="${jndi.devPool}"/>

Resources