Cannot use #NotBlank - java

I just started working with spring and I'm trying to use #NotBlank. Problem is it is not working. In pom.xml I have this dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
<version>2.7.1</version>
</dependency>
The error I'm getting is this:
This is my import:
import javax.validation.constraints.NotBlank;
and I'm also getting this error:
I have searched similar questions and the answer is that by adding this dependency and restarting IDE will work. In my case it's still not working. Any suggestions?

Add a dependency on javax.validation:validation-api:2.0.1.Final. That defines the validation API (i.e. the interface) but does not implement it. spring-boot-starter-validation has a dependency on hibernate-validator which is the reference implementation of Java's validation API.
You imported the implementation but not the interface which is why your IDE was complaining. By importing both the interface and the implementation that code should compile.

Related

Why is 'boolean com.sun.mail.util.PropUtil.getBooleanSessionProperty(javax.mail.Session, java.lang.String, boolean)' not found?

I'd like to write some tests for particuar classes. Yet, I want to read in an EML file. This works fine by using
IOUtils.toString(r.getInputStream(), StandardCharsets.UTF_8);
I have a class which is (normally) able to read such an EML (by InputStream, filename or file content(String)) what is done so far in multiple places in the project. When I try to do this in a test class I get this:
java.lang.NoSuchMethodError: 'boolean com.sun.mail.util.PropUtil.getBooleanSessionProperty(javax.mail.Session, java.lang.String, boolean)'
at javax.mail.internet.MimeMessage.initStrict(MimeMessage.java:320)
at javax.mail.internet.MimeMessage.<init>(MimeMessage.java:215)
at d.d.a.c.e.EmlFileHolder.buildByEmlFile(EmlFileHolder.java:103)
at d.d.a.c.e.EmlFileHolder.buildByEmlFileStream(EmlFileHolder.java:99)
at d.d.a.c.e.EmlFileHolder.buildByEmlFileString(EmlFileHolder.java:81)
Maybe a problem with the dependencies? (But I couldn't solve or even figure out the problem.) Here, the imported dependencies related to mail, MimeMessages, ...
<dependency>
<groupId>jakarta.mail</groupId>
<artifactId>jakarta.mail-api</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>jakarta.mail</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.simplejavamail</groupId>
<artifactId>simple-java-mail</artifactId>
<version>${simple-java-mail.version}</version>
</dependency>
<dependency>
<groupId>org.simplejavamail</groupId>
<artifactId>smime-module</artifactId>
<version>${simple-java-mail.version}</version>
</dependency>
You appear to be mixing code that uses the old javax.mail.* APIs (and thus com.sun.mail.*) with the new jakarta.mail 2.0 API and implementation.
I suspect you managed this by updating to jakarta.mail in the POM but keeping ${simple-java-mail.version} at 6.7.x or earlier. (This is an inference. It is not clear from your question what version you are actually using.)
If you are going to use jakarta.mail 2.0 and later, you need to use simple-java-mail 7.0 or later.
Alternatively, you could wind back to an earlier version of javax.mail. (There are jakarta.mail 1.6.7 artifacts in Maven Central, but the are apparently just the corresponding javax.mail artifacts renamed.)

Unable to import com.vaadin.data.util.PropertysetItem

Just tried importing PropertysetItem after adding vaadin dependency which I have mentioned below but was unable to import. Can anyone help me for finding the right dependency
dependency added
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-compatibility-server</artifactId>
<version>8.4.0</version>
</dependency>
PropertysetItem as well as other related classes have been moved to the com.vaadin.v7.data.util package. You thus need to update your import statements to take the new package name into account.

Why is Java saying I can't use #NotBlank with a string

I have the following code
import javax.validation.constraints.NotBlank;
...
#NotBlank(message="Not Blank")
private String thing;
When I try to run I get
No validator could be found for constraint 'javax.validation.constraints.NotBlank' validating type 'java.lang.String'
How do I use NotBlank annotation with a string?
Java 8
The javax.validation.constraints.NotBlank annotation you are applying is part of Bean Validation API v2.
The most probable case is:
You have bean validation API v2 as dependency on your project
The implementing framework/library supports only v1.0/v1.1 API.
Please check on this post for information about existing implementations: Is there JSR-303 implementation available?
I recommend you checking for bean validation API v2 on your classpath (it also can be called JSR-380). The only implementation of this API I know about is Hibernate Validator v6.0. Make sure that v2 implementation is not hidden by some v1.x implementation being on classpath.
I have encountered this problem and solved it. Because the validation version conflicts,
In my project, the error was introduced twice validate。check the jar package, and then remove, then successful。
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.1.0.Final</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
</dependency>

Where is the maven dependency for ConfigurableEmbeddedServletContainerFactory?

I am trying to follow this example for setting up SSL with Tomcat in Spring Boot. The example is unfortunately missing the import statements, so I tried to infer the correct import statement for ConfigurableEmbeddedServletContainerFactory.
However, I still encounter the following error:
The import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainerFactory cannot be resolved
I think this means I am missing the maven dependency for this particular class. Can anyone point me to what this is?
from code for file package is org.springframework.boot.context.embedded
maven dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>x.x.x</version>
</dependency>

java.lang.NoSuchMethodError: org.apache.log4j.Logger

We use ivy to manage a multi project java application, and recently this error started showing up when we do builds. What's causing this?
This was fixed by adding the following line to the end of the dependencies section in ivy.xml:
<dependencies>
<exclude module="log4j-over-slf4j" />
</dependencies>
Why was it an issue?
Looks like the log4j bridge for sjf4j has an incomplete implementation
This url explains it in more detail.
It looks like the log4j bridge does not implement the full interface for log4j . If you are still using direct log4j calls, you will need both the slf4j bridge jar and the log4j jar
In your case it looks like you excluded the bridge jar, so all slf4j calls go directly to log4j instead of the bridge.
If your code invokes log4j through the xml file , this will work. However if your code programatically invokes log4j initialization this bridge is not going to work
I know this is a very old question but I wanted to share what worked out fine for me. If you have different artifacts of slf4j-log4j* for two projects that are interdependent on each other, for example spring data jpa and spring MVC, this happens. Keep it consistent or even better have a parent pom. In my case I had slf4j-log4j12 on my spring data jpa project and slf4j-log4j13 on my spring MVC one.
Comment this dependency from the pom.xml
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j13</artifactId>
<version>
</dependency>
And add (or keep) the following one:
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.12</version>
</dependency>
Wherever you see a compile time error regarding Log4j, add the following import:
import org.apache.log4j.Logger;

Categories

Resources