I am new to maven and keycloak.
I am trying to write a simple extension for keycloak and following the tutorial from the docs.
The problem is that even though I have defined keycloak in my dependencies in pom.xml, I am unable to import them in my code.
Here are the images of my snippet
pom.xml
image
/src/main/java/com/example/rest/HelloResourceProviderFactory.java
image
Just for testing, I tried to put spring in pom.xml, and I was able to import that.
Is there some different procedure for creating an SPI for keycloak? or is there a different way to import keycloak dependencies.
You are missing the version for your keycloak dependencies
Change pom.xml and add a property for your keycloak version (e.g. 6.0.1).
Use the version parameter in all your keylocak dependencies.
<project ...>
<artifactId>...</artifactId>
...
<properties>
<keycloak.version>6.0.1</keycloak.version>
</properties>
<dependencies>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-core</artifactId>
<version>${keycloak.version}</version>
<scope>provided</scope>
</dependency>
...
Related
I am new to spring boot world and encountered with an issue. I have a requirement of using mssql in my project which I am default getting as a dependency from spring-boot-starter-parent but the catch is the version which is getting inherited is what i do not want.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
<type>pom</type>
</dependency>
This will give me mssql version mssql-jdbc : 6.1.0.jre7 (Which i do not want)
My organization has a dedicated BOM POM created for all the common components used in all the projects which includes mssql latest version. mssql-jdbc :8.4.1.jre8
I have declare this BOM POM under dependencyManagement tag.
<dependencyManagement>
<dependencies>
<dependency>
<grpId></grpId>
<artifactiID></>
<version/>
</dependency>
</dependencies>
</dependencyManagement>
Now my POM is only taking mssql version from spring boot parent (Which is obvious as per the tree hierarchy) but i want to use version from BOM POM.
I also don't want to hardcode the mssql version in my pom dependency like
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>It should take from the BOM POM declared in dependency management</version>
So that whenever a new version got updated in my BOM POM, it should reflect directly in my application POM file.
my question can be repetitive or easy to figure out but as i am new to the spring world, Your help will be helpful for sure.
Thanks is advance.
Not possible.
Parent POM versions are stronger than BOM versions.
You need to add the version explicitly in your POM and change it manually when the BOM changes.
To override the version of a dependency you have to find how it was defined in the parent POM. Example in your case, if you look at the Spring Boot parent POM, in the <properties> section, you should see something like:
<mssql.version>Y.XX</mssql.version> <!-- please note that I am not really sure about the property name but I am 100% that the version is defined as a property-->
Then copy-paste that property in the <properties> section of your POM and set the version you want.
I'm trying to use auth0 and JWT in my Spring Boot project. I have imported these dependencies:
<dependency>
<groupId>com.auth0</groupId>
<artifactId>auth0-spring-security-api</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>3.8.1</version>
</dependency>
I also use JwtWebSecurityConfigurer to configure spring security.
If I use only auth0-spring-security-api, JwtWebSecurityConfigurer works correctly and checks my token. But I can't use the JWT class that is contained in java-jwt artifact.
If I import both dependencies in pom, it stops working and when Spring security checks my token, I get an error:
java.lang.NoSuchMethodError: com.auth0.jwt.interfaces.Verification.withIssuer(Ljava/lang/String;)Lcom/auth0/jwt/interfaces/Verification;
Also, I know that java-jwt library is a dependency of auth0-spring-security-api, I think that there's a sort of collision with two libraries. Does anyone have a solution? Thanks
Solved! If anyone has this problem, the solution is:
Check your pom.xml and the pom of auth0-spring-security-api. The java-jwt dependency imported from auth0-spring-security-api must be the same of java-jwt in your pom.
I am very new to Neo4j and I want to get started with an embedded Neo4j in a Java Application.
I try to create an HelloWorld Application like the following:
https://neo4j.com/docs/java-reference/current/#tutorials-java-embedded
You can find the source code here:
https://github.com/neo4j/neo4j/blob/3.1/manual/embedded-examples/src/main/java/org/neo4j/examples/EmbeddedNeo4j.java
I created a new maven project and added org.neo4j:neo4j 3.0.3 as a dependency. Unfortunately I cannot import "org.neo4j.graphdb.factory.GraphDatabaseFactory", all other imports seem to be ok.
Now I figured out, that the import is working for version "3.1.0-SNAPSHOT" of the neo4j dependency.
Here you can find the relevant part of my pom-file:
<dependencies>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>
<version>3.1.0-SNAPSHOT</version>
</dependency>
</dependencies>
Because I want to use a stable version, I want to achieve this with version 3.0.3 as well, but I cannot find something that this factory is depending on this version or how you should do it at version 3.0.3. Can somebody provide information about this?
The dependency you should include in your pom.xml is
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>
<version>3.0.3</version>
</dependency>
As I see you already included the right dependency. Then I guess something went wrong during the resolving. Therefore purge your local repository and resolve the dependency again with following command
mvn dependency:purge-local-repository -Dinclude=org.neo4j:neo4j
If it's still not working you have to check if you are resolving the artifact from the maven central repository or somewhere else.
I have project which used JIRA REST Java Client. It worked fine until I tried to integrate it with Spring Boot. Since that I am not able to invoke createWithBasicHttpAuthentication from AsynchronousJiraRestClientFactory without error. I get:
ClassNotFoundException: org.apache.http.util.Args
So I added HttpComponents Core blocking I/O(httpcore) dependency to my pom.xml, but I after that I got
ClassNotFoundException: org.apache.http.nio.NHttpMessageParserFactory
Which I resolved with adding HttpComponents Core non-blocking I/O(httpcore-nio) to pom.xml. Now I have
NoSuchMethodError: org.apache.http.nio.client.HttpAsyncClient.start()V
I've compared dependency:tree when project has spring boot parent and when it's commented out. It shown me that adding spring boot parent changes versions of my dependencies. You can check diff here( on left without spring boot, on right with spring boot)
It seems that JIRA REST Java Client need older versions of some dependencies.
How can I solve this problem?
pom.xml
...
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.0.0.RELEASE</version>
</parent>
...
<dependencies>
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-rest-java-client-core</artifactId>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.3.2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore-nio</artifactId>
<version>4.3</version>
</dependency>
</dependencies>
...
I was able to fix runtime in my Spring Boot application by overriding these properties in my pom.xml
<properties>
<httpasyncclient.version>4.0-beta3-atlassian-1</httpasyncclient.version>
<httpclient.version>4.2.1-atlassian-2</httpclient.version>
</properties>
Note that there can be other problems if you decide to use http-client and/or httpassync client in your project (eg. using RestTemplate).
Atlassian should definitely upgrade the dependencies.
I need some help with setting up a spring project.
I am busy going through the book “Spring in action” and I need to try some of the examples out. I have looked at plenty of pages and nowhere can is see where I am going wrong. It must be something silly that I missed or overlooked.
I installed Spring source tool suite
Created a new java/maven project
Added a new applicationContext.xml bean definition file
The outline of the project looks as follows
I created my beans (vwCar & nissanCar that implements car interface) and where it comes to use them I have a main method in the app class. I need to create an application context.
ApplicationContext context = new ClassPathApplicationContext("src/main/resources/applicationContext.xml");
But I have difficulty creating the ApplicationContext. It gives me an error and code assist don’t work
Using code assist the only thing that it suggests is (Pressing Ctrl+Space after typing app):
If I just type it out I get an error
ApplicationContext cannot be resolved to a type in class App.java
Is there something that I should import myself?
I can see an "S" on the project folder - doesn't this indicate that the project is already spring enabled?
---------ADDED AFTER ALEX COMMENTED TO SUGGEST THAT I SHOULD ADD A MAVEN DEPENDENCY-------------
I added the missing dependency like Alex suggested but I don't know what the correct version is. If I look a the STS directory I see several files named ... 2.9.2
org.springframework.ide.eclipse.feature_2.9.2.201205070117-RELEASE
but if I add the dependency with 2.9.2 i get the following error on my POM
Missing artifact org.springframework:spring-context:jar:2.9.2
My POM looks like below
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>my.chrispie</groupId>
<artifactId>MyMavenSpringProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>MyMavenSpringProject</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>2.9.2</version>
</dependency>
</dependencies>
</project>
Since you're using Maven you should add the following dependency to your pom.xml:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework-version}</version>
</dependency>
Where ${org.springframework-version} should be replaced with the version you are using.
This will ensure that the Spring jars needed to get started are available to your application.
It must be something silly that I missed or overlooked.
I think you'v just overlooked the dependency management functionality of Maven. Creating a Java/Maven project doesn't pull in the required Spring jars. If you used a template project from the STS landing page this would all have been setup for.