How to read values from ldap using spring-ldap - java

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.

Related

Can I use multiple and different databases in the same Quarkus app?

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.

Using Spring-Boot-Starter-Web in combination with ObjectDB

I am implementing a program in Spring-Boot using ObjectDB. To actually use ObjectDB I have followed this approach which is working perfectly.
However, as soon as I want to use `spring-boot-starter-web`` then I am getting the following errors:
dataSource or dataSourceClassName or jdbcUrl is required. at
com.zaxxer.hikari.HikariConfig.validate
I have been fiddling around with parameter jdbc-url in the properties file as mentioned in many posts. Tried to exclude Hikari because probably ObjectDB uses his own connection pooling mechanism. But without any results.
Any ideas on how to solve this error?
I am using the exact same code as in the link. I have added Spring-Actuator in the pom like this:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
In some cases, frameworks that use JPA require specifying a JDBC connection details, including a JDBC driver, which is then passed to the JPA implementation and used by it to access the database. ObjectDB is a JPA implementation that does not access an external database, and therefore, does not need or use a JDBC driver.
As discussed in the comments to the question, a simple workaround is to specify a dummy JDBC driver, which will be passed to ObjectDB and then ignored. It does look weird, but this is the way to go until either ObjectDB implement its own JDBC driver, or the relevant frameworks become more flexible regarding their request of a JDBC driver.
Have you tried this (in the pom.xml?):
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.objectdb</groupId>
<artifactId>objectdb</artifactId>
<version>2.8.4</version>
</dependency>
And don't forget to add the database connection in application.properties:
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=mydbuser
spring.datasource.password=mydbpass
spring.datasource.url=jdbc:....
See https://www.baeldung.com/the-persistence-layer-with-spring-and-jpa for more details.

Spring Boot-Activiti Integration with Sybase Database

I created a spring-boot project to read and write data to Sybase database. The project was working as intended. However, whenever I added activiti dependencies, It says "couldn't deduct database type from database product name 'Adaptive Server Enterprise'". According to my understanding, there are some classes conflicting each other in activiti and spring even though I do not use anything regarding activiti( except the fact that I just opened a folder called processes in the resources directory).
The activiti dependencies I added are:
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-basic</artifactId>
<version>5.21.0</version>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-rest-api</artifactId>
<version>5.21.0</version>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-actuator</artifactId>
<version>5.21.0</version>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-jpa</artifactId>
<version>5.21.0</version>
</dependency>
To clarify my point in this, I wanted to use activiti just for workflow purposes and leave the rest of the ETL or database job to spring. If I change database from Sybase to Mysql, the project also works fine even with activiti dependencies. As far as I know activiti has no support for Sybase and apparently, it tries to interfere everything possible and overrides something that was already working at the first place. How can I overcome this problem?
you are trying to use the spring boot starter which automatically tries to configure a database using spring autoconfiguration. Can you clarify with which database do you want to use Activiti? If you want to use Sybase you will need to contribute back to the project with Sybase support. Alternatively, you can not use the starter and depend on the engine directly, this will push you to provide the engine configurations for your spring environment. You can also check the -starter project and adapt as needed.
HTH

Exception when trying to use spring data mongo repository with Stream

I have MongoRepository extended and want to use the Stream API. As by the reference, I declared a query method:
public Stream<MyType> findByIdIn(Iterable<? extends String> myTypeIds);
However, when starting up my Spring Boot application, a PropertyNotFoundExceptionis thrown stating:
No property id found for type Stream!
My domain type derives from a supertype containing the actual id of the MongoDB object. Any ideas how to fix this?
I am using Spring Boot 1.2.0.RELEASE and Spring Data MongoDB 1.6.1.RELEASE.
Support for Stream as a return-type was added in Spring Data MongoDB version 1.7, as per the release notes:
What’s new in Spring Data MongoDB 1.7
...
Allow Stream as query method return type
Therefore, you need to update from 1.6.1.RELEASE to at least version 1.7. If you are using Maven, you could add the following dependency for the current latest version, which is 1.8.2.RELEASE:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>1.8.2.RELEASE</version>
</dependency>

Integrate redis with spring boot

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

Categories

Resources