I get an error when trying to set up Spring MVC validation.
javax.validation.ValidationException: Unable to find a default provider
I read in the documents that the default provider they use is the hibernate-validator. Do I need to include this library to get validation to work? Is it okay to include this library even though i'm not using hibernate for my project?
If you are using Maven, you must add a dependency to the Hibernate Validator Annotation Processor.
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator-annotation-processor</artifactId>
<version>4.1.0.Final</version>
</dependency>
You can find it in the JBoss repository :
<repository>
<id>JBoss Repository</id>
<url>https://repository.jboss.org/nexus/content/repositories/releases</url>
<name>JBoss Repository</name>
</repository>
Yes, you should include Hibernate Validator library in order to use it. It doesn't depend on Hibernate itself.
Make sure you're using Hibernate 4.
Related
I'm trying to use the PokeAPI for a Java Project. It should work, however, when I try to add the dependancy to my pom.xml, it doesn't recognise it. I have the files downloaded from the github, and have the following code in my pom.xml:
<dependency>
<groupId>me.sargunvohra.lib</groupId>
<artifactId>pokekotlin</artifactId>
<version>2.3.0</version>
</dependency>
files
But I keep getting this error:
Could not find artifact me.sargunvohra.lib:pokekotlin:pom:2.3.0 in
central (https://repo.maven.apache.org/maven2)
Does anyone know how to properly add this dependency? The code below does not work when I try to use it.
PokeApi pokedex = new PokeApiClient ();
PokemonSpecies pokemon = pokedex.getPokemonSpecies (1);
System.out.println(pokemon);
P.S. I have tried to invalidate cache and restart, that does not work either.
The artifact is located at Spring Plugins repository (https://repo.spring.io/plugins-release/) so you need to add it to your pom.xml as follows:
<repositories>
<repository>
<id>spring-plugins-release</id>
<name>Spring Plugins</name>
<url>https://repo.spring.io/plugins-release/</url>
</repository>
</repositories>
I need to use JIRA REST client version 5.2.0 or higher. Cloud JIRA does not work with an earlier version of the client.
In my pom.xml file I have the following dependencies:
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-rest-java-client-core</artifactId>
<version>5.2.1</version>
</dependency>
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-rest-java-client-app</artifactId>
<version>5.2.1</version>
</dependency>
When I building the project, I get an exception like this:
Failed to execute goal on project XXXXXXXXX: Could not resolve dependencies for project XXXXXXXXXX:jar:XXXX: Failed to collect dependencies at com.atlassian.jira:jira-rest-java-client-core:jar:5.2.1: Failed to read artifact descriptor for com.atlassian.jira:jira-rest-java-client-core:jar:5.2.1: Could not find artifact com.atlassian.platform:platform:pom:3.1.7 in MY_REPO (http://XXXXXXXXXX/repository/maven-public) -
com.atlassian.platform:platform:pom:3.1.7 is not listd at mvnrepository. There are versions 3.1.12 and 3.1.17, but not 3.1.7. Someone told me that version 3.1.7 might have had a security-related bug and was therefore removed by Atlassian.
Both jira-rest-java-client-app and jira-rest-java-client-core are children of jira-rest-java-client-parent, which uses version 3.1.7 of the platform:
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-rest-java-client-parent</artifactId>
<version>5.2.1</version>
<packaging>pom</packaging>
[...]
<properties>
<platform.version>3.1.7</platform.version>
[...]
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.atlassian.platform</groupId>
<artifactId>platform</artifactId>
<version>${platform.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
5.2.1 seems to be the latest version of both jira-rest-java-client-core and jira-rest-java-client-app.
How can I use the JIRA REST client (for programmatically creating issues in Cloud JIRA) when it uses a version of the library that is not available any more?
I tried to exclude the platform in the dependencies and to specify another version in depencency management sections. This did not help.
The accepted answer is absolutely correct. A concrete example on how to be able to get the artifacts from https://packages.atlassian.com, for anyone coming here looking for answers, would be to include a repository element for it in your pom, like so:
<repositories>
<repository>
<id>atlassian-public</id>
<url>https://packages.atlassian.com/maven/repository/public</url>
</repository>
</repositories>
A WORD OF CAUTION, THOUGH: The jira-rest-java-client was created for use with Jira Server, not Jira Cloud
Some months ago, Atlassian made changes to Jira Cloud which made it impossible to use the jira-rest-java-client (JRJC) for things such as searches in Jira Cloud. As far as I can tell they don't intend to make the JRJC library compatible with Jira Cloud anymore. Atlassian has provided an article on how to generate a REST client for Jira Cloud, but as far as I know, they haven't created any Jira Cloud libraries similar to the JRJC.
If you have a look at the repository
https://packages.atlassian.com/mvn/maven-external
from atlassian, you find the desired artifact com.atlassian.platform:platform:pom:3.1.7there. Since this repository seems to be from atlassian, I see no reason to believe that they recommend not to use the version.
This is also discussed in https://community.atlassian.com/t5/Jira-questions/Jira-rest-java-client-core-5-1-and-fugue-2-7-0-breaks-build/qaq-p/1151091
I need to use AuthenticationRequest in my Maven Java Project. I did a search on the internet and found AuthenticationRequest on this page (OpenID Connect authentication), indicating this library contains AuthenticationRequest. I follow the links on that website to this page (com.nimbusds:oauth2-oidc-sdk-6.13 API Doc) and find a list of packages. I found this library at Maven Repository.
I added the information in my pom.xml in my Maven Project in Eclipse. Updated Project. Yet I am not able to import any packages starting with "com.nimbusds.oauth2".
Here is the dependency info for that library that I put in my pom.xml file:
<!-- https://mvnrepository.com/artifact/com.nimbusds/oauth2-oidc-sdk -->
<dependency>
<groupId>com.nimbusds</groupId>
<artifactId>oauth2-oidc-sdk</artifactId>
<version>6.13</version>
<scope>runtime</scope>
</dependency>
I am following an example code that uses the AuthenticationRequest class. I am having trouble finding the Maven info to put in my pom.xml file that allows me to use that class in my project. How do I find the right info for it?
Since you are developing a class that depends on that AuthenticationRequest class to compile, your maven goal is going to be before runtime. Maven scope of runtime is not appropriate.
You need to modify your pom.xml to specify compile scope:
<dependency>
<groupId>com.nimbusds</groupId>
<artifactId>oauth2-oidc-sdk</artifactId>
<version>6.13</version>
<scope>compile</scope>
</dependency>
Since Maven's default scope is compile, you could also just omit the scope tag.
Maven will import dependencies from the Maven Central repository by default. If Maven Central doesn't contain your dependency (I haven't checked) you must specify a repository that does contain it with something of this form in your pom.xml (note the repo is just an example - substitute a real one that contains your dependency)
<repositories>
<repository>
<id>some-example-repo</id>
<url>http://some.example.repo/some_example_path/</url>
</repository>
</repositories>
I would like to ask two questions about the Spring Cloud Config.
1) Is it possible to do an implementation of Spring Cloud Config Server to recover the properties of a base mongodb instead of git?
2) The Spring Cloud Config Client Setup automatically update when you have a change in ownership in Spring Cloud Config Server?
Thanks!!!
Spring Cloud Config Server MongoDB is now available on Github.
To get it up and running all you need to do is add the maven config as below, add #EnableMongoConfigServer to your Spring Boot application configuration and configure desired spring.data.mongodb.* properties.
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server-mongodb</artifactId>
<version>0.0.1.BUILD-SNAPSHOT</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>ojo-snapshots</id>
<name>OJO Snapshots</name>
<url>https://oss.jfrog.org/artifactory/libs-snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
Then you can add configuration documents to MongoDB like this:
db.appname.insert({
"label": "master",
"profile": "prod",
"source": {
"user": {
"max-connections": 1,
"timeout-ms": 3600
}
}
});
And access them via http://localhost:8080/master/appname-prod.properties to obtain a response like this:
user.max-connections: 1.0
user.timeout-ms: 3600.0
UPDATE
We have upgraded spring-cloud-config-server-mongodb to use spring-boot 1.5.7 snapshots.
Yes, it is possible, pull requests are welcome
There is no push, but you can use spring's #Scheduled to call
RefreshEndpoint.refresh() on an interval basis.
Not sure about 1.
For 2) You have spring-cloud-bus which can provide push notifications to all the clients automatically when you make a change in the config server.
http://cloud.spring.io/spring-cloud-config/spring-cloud-config.html
Following are needed:
1. RabbitMQ/ Redis running locally
2. Add this dependency in config server pom xml. Use Brixton.M5 build.
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-parent</artifactId>
<!-- <version>Brixton.BUILD-SNAPSHOT</version> -->
<version>Brixton.M5</version>
<relativePath />
</parent>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-monitor</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
3. Use the bus dependency in addition to the spring-config-client dependencies you might already have:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
4. [POST]http://localhost:/monitor?path= - this should push notifications to the clients. Alternately you can use a github webhook to post automatically where there is a change in the file.
You can refer to the post here
1. I recommend this git projecto to do that: https://github.com/spring-cloud-incubator/spring-cloud-config-server-mongodb
2. First, after make all your changes, add the #RefreshScope tag to your rest controller if you don't have it, like this:
#RefreshScope
#RestController
class MessageRestController {
#Value("${message:Hello default}")
private String message;
#RequestMapping("/message")
String getMessage() {
return this.message;
}
Next you need send an empty HTTP POST to the client’s refresh endpoint like this:
http://localhost:8080/refresh
note: you can use RESTclient plugin or POSTMAN in your browser to do that.
Finally probe the new message after a few seconds http://localhost:8080/message
note: this example is for client by default configuration...
I am new to EHCache and tried to use it as our cache server. I wrote the code trying to get started:
public class CacheMap {
private static CacheManager cacheManager=new CacheManager("ehcache.xml");
private static Cache cache=cacheManager.getCache("firstCache");
}
In classpath, I have included terracotta-toolkit-1.6-5.2.0.jar, terracotta-toolkit-1.6-runtime-5.0.0, slf4j-api-1.6.6, slf4j-jdk14-1.6.6, ehcache-2.7.0 and ehcache-ee-2.7.0
And I have ehcache.xml in my root directory.
However, I have got the following error on first line of my code:
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: net.sf.ehcache.CacheException: Could not create ClusteredInstanceFactory due to missing class. Please verify that terracotta-toolkit is in your classpath.
at net.sf.ehcache.terracotta.TerracottaClusteredInstanceHelper.newClusteredInstanceFactory(TerracottaClusteredInstanceHelper.java:187)
at net.sf.ehcache.terracotta.TerracottaClient.createNewClusteredInstanceFactory(TerracottaClient.java:169)
at net.sf.ehcache.terracotta.TerracottaClient.createClusteredInstanceFactory(TerracottaClient.java:126)
at net.sf.ehcache.CacheManager.doInit(CacheManager.java:442)
at net.sf.ehcache.CacheManager.init(CacheManager.java:392)
at net.sf.ehcache.CacheManager.<init>(CacheManager.java:291)
at CacheMap.<clinit>(CacheMap.java:7)
Any ideas how to get Terracotta working?
I think you have mixed required terracotta jars. If you use maven here are the dependencies for terracotta ver. 3.6.5 (the last version compatible with JDK5):
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core-ee</artifactId>
<version>2.5.6</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-terracotta-ee</artifactId>
<version>2.5.6</version>
</dependency>
<dependency>
<groupId>org.terracotta</groupId>
<artifactId>terracotta-toolkit-1.5-runtime-ee</artifactId>
<version>4.5.0</version>
</dependency>
Also don't forget to point to terracotta's maven repository to download required jars:
<repository>
<id>terracotta-repository</id>
<url>http://www.terracotta.org/download/reflector/releases</url>
<releases>
<enabled>true</enabled>
</releases>
</repository>
If you are not using maven, then you should have on your classpath the following jars:
ehcache-core-ee-2.5.6.jar
ehcache-terracotta-ee-2.5.6.jar
terracotta-toolkit-1.5-runtime-ee-4.5.0.jar