How can i integrate redis with spring boot?
After add the below dependecy, what would be the code structure for simply saving user details list where user name is the key and User object is the value in redis server. Then fetch a user details with a given user name?
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-redis</artifactId>
<version>1.2.7.RELEASE</version>
</dependency>
Take a look at this example ... https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-data-redis
Check this answer which is similar but with slightly different question
spring-data-redis redisTemplate Exception
Related
I want my Quarkus app to connect to both a PostgreSQL database and a MySQL database.
I've researched through https://quarkus.io/guides/datasource#multiple-datasources and https://quarkus.io/guides/hibernate-orm#multitenancy, but could not figure out if this is possible.
my application.properties is as below;
quarkus.datasource.postgresql.db-kind=postgresql
quarkus.datasource.postgresql.username=xyz
quarkus.datasource.postgresql.password=xyz
quarkus.datasource.postgresql.jdbc.url=jdbc:postgresql://localhost:5432/xyz
quarkus.datasource.mysql.db-kind=mysql
quarkus.datasource.mysql.username=xyz
quarkus.datasource.mysql.password=xyz
quarkus.datasource.mysql.jdbc.url=jdbc:mysql://localhost:3305/xyz
my pom.xml has both;
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-postgresql</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-mysql</artifactId>
</dependency>
Is it possible to connect to multiple different types of database from Quarkus?
How do I persist() an Entity to the correct database if such capability exists?
Thank you!
What you are asking for is supported, see this part of the datasource documentation and this part of the Hibernate ORM documentation.
I want to be able to use my Entities classes / documents created with Java Spring in order to create my MongoDB Database at Runtime abd see the different fields of the documents and collections and this automatically when running my spring boot application.
I use the property in my application.properties.
hibernate.ogm.datastore.create_database=true
and as a dependency in pom.xml :
<dependency>
<groupId>org.hibernate.ogm</groupId>
<artifactId>hibernate-ogm-mongodb</artifactId>
<version>5.4.1.Final</version>
</dependency>
The application launches but the associated database is not created, What am i missing here,
Thank you.
I went via almost all docs and all but not able to get grip on this mysterious stuff.
so my question - Can I use my standalone spring boot app to monitor health and other metrics of my app via http jmx url? Do I need to configure something else for this?
I have added below dependency in boot app.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.jolokia</groupId>
<artifactId>jolokia-core</artifactId>
</dependency>
I have also configured below properties in my config file.
management.endpoints.web.exposure.include=*
management.endpoints.jmx.unique-names=true
management.server.port=8080
management.server.ssl.enabled=false
When I try to hit URL : http://localhost:8080/actuator/jolokia/health I am not able to see any results.
Also tried adding custom end point like below but not working.
#Endpoint(id="mypoint")
#Component
public class myPointEndPoint {
#ReadOperation
public String mypoint(){
return "Hello" ;
}
with additional property
management.endpoint.mypoint.enabled=true
The problem is the url you are trying to invoke.
First, retrieve the possible mbeans with: http://localhost:8080/actuator/jolokia/list
When you take a look at the Health mbean, you must provide the unique name and the operation (op).
In my case, it looked like: http://localhost:8080/actuator/jolokia/exec/org.springframework.boot:type=Endpoint,name=Health,identity=4200098/health
Also check the Jolokia documentation: https://jolokia.org/reference/html/index.html
I am trying to read values from ldap using spring-ldap.
I am trying to follow ldap query based on the document
http://docs.spring.io/spring-ldap/docs/current/reference/#basic-queries
My program is failing to compile because LdapQuery is not found.
LdapQuery query = query()
.base("dc=261consulting,dc=com")
.attributes("cn", "sn")
.where("objectclass").is("person")
.and("sn").is(lastName);
My pom.xml has the following entry.
<dependency>
<groupId>org.springframework.ldap</groupId>
<artifactId>spring-ldap-core</artifactId>
<version>1.3.1.RELEASE</version>
</dependency>
I looked at spring-ldap api documentation at http://docs.spring.io/spring-ldap/site/apidocs/index.html and they dont seem to have LdapQuery class.
Can you please help on how to read values from ldap using spring? If you can provide an example, that will be great.
Thanks
LdapQuery was added with 2.0. If you're constrained to an earlier version consider using LdapTemplate.
I am in dilemma to store session in redis using Spring and there are many methods and concepts to handle this issue. Some methods are listed below:
Spring Data Redis
Spring Session
Spring Session Manager
Now the question is what is the best combination to store (delete and so on) session in redis using spring.
I will be appreciated if someone help me with a simple explanation.
You're a little confused:
Spring Data Redis provides easy configuration and access to Redis from any type of Spring applications. It realize both low-level and high-level abstractions for interacting with the Redis store. In few words - just realization of Redis client library.
Spring Session provides an API and implementations for managing a user’s session information.
Spring Session Management is just a HTTP session related functonality focused to concurrency control, filtering and authentication strategy and do not work with Redis as is. it works with interfaces only.
Using Spring framework you are using Spring Session. You need only configure it to use Redis as backend as in official documentation sample and sample project with Redis session in spring application.
If you are using spring boot, then the changes you need for your application is pretty simple.
Add the following dependencies and add redis connection configuration in application.properties and you are good to go.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
</dependency>
I have a details post about this at https://springhow.com/spring-boot-security/session-redis/