I am getting ready to take my Spring Certification v5.0 and there appears to be a question: Do you use Spring in a unit test? Link to Exam Guide questions. From Spring reference guide I know this: The POJOs that make up your application should be testable in JUnit or TestNG tests, with objects simply instantiated using the new operator,
Tag: spring
Spring unit test issue with Validator
I am trying to write unit test for a validator class that I have. So within my UniqueEmailValidator class, I injected a @Service component to check if it exist. And I tried to write unit test for this constraint validator. How do I initialize the AccountService within the Validator class? It seem like it wasn’t injected, hence, the null exception.
How to add security for spring 5 websockets
I followed the following tutorial: Using WebSocket to build an interactive web application Everything works as described and aplication looks fine. I just have a nice controller: And a bit configuration. Now I want to add security for this simple application. I spent time to find an example but I could not find it. Generally I’ve found the tutorial: Preview
Page vs Slice when to use which?
I’ve read in Spring Jpa Data documentation about two different types of objects when you ‘page’ your dynamic queries made out of repositories. Page and Slice So, I’ve tried to find some articles or anything talking about main difference and different usages of both, how performance changes and how sorting affercts both type of queries. Does anyone has this type
java.lang.ClassNotFoundException: Cannot find implementation for
I need help with the following error: UserMapper interface has annotation. I use eclipse Neon with buildship plugin, org.mapstruct and spring are imported with Gradle. It works without this error on my colleague’s IntelliJ Code for UserMapper: From what I read it could do something with compiler failing to connect auto-generated code (Gradle does not set anything in AnnotationProcessing>FactoryPath) Answer
How to get List from Object in Spring RestTemplate
How to get List from Object? Below you can find my code: Actually object variable is a List of Objects(Strings) and I need to get all these Strings. If I print it out System.out.println(object.toString()); it looks like that: I need to get List of these Strings to dynamic use it. Could you please help? Answer Try this out. This should
Spring Security 5 : There is no PasswordEncoder mapped for the id “null”
I am migrating from Spring Boot 1.4.9 to Spring Boot 2.0 and also to Spring Security 5 and I am trying to do authenticate via OAuth 2. But I am getting this error: java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id “null From the documentation of Spring Security 5, I get to know that storage format for password is
Spring MessageSource fallback to explicit locale
In some spring boot application, i18n is used. Here is the config: There is a requirement to obtain a locale from header Accept-language, falling back to “en” if: the header is missing, the header has wrong value, the config is missing for the locale. Two first points are resolved by provided LocaleResolver (see config). However, I don’t know how to
Spring MVC with hibernate validation doesn’t work
I have some problems with hibernate validations with Spring. I did everything as explained in an online tutorial, but it’s not working and I just go to the next page without validation error. Controller: customer-form.jsp So, there are no errors in BindingResult when I have an empty field for lastName. What am i doing wrong? Answer Add hibernate-validator in your
Cannot forward to error page for request … as the response has already been committed. As a result, the response may have the wrong status code
I am using Spring Boot 2.0.0.RELEASE, Thymeleaf, Spring Security, JDK 10, Apache Tomcat 9.0.6 . I have controller at application.properties I have I have configuration class When I access http://localhost:8081/cash/ccy or http://localhost:8081/cash/vy I see the same error … The full console log is https://gist.github.com/donhuvy/ad3f65955292d9874805c99c03f3227f#file-console-log-L450 How to fix it? Answer I am missing Thymeleaf dependency. I must add this line to