Why we needs to use @service inside the service Implementation and @repository in the DAO Implementation. There are no problem occur when I interchange the @service and @repository annotation in the spring MVC. Answer According to documentaion @Repository,@Service,@Controller are all synonyms. They all are just specializations of @Component annotation. So, generally, they can be used one instead of other. But
Tag: spring-mvc
Spring Boot @ExceptionHandler hide Exception Name
I am using Spring Boot 1.3.X and have the following: Which works as expected. When passing a wrong param, the following exception is raised: I then created an ExceptionHandler as seen below: Which raises the following Exception: Is it possible to exclude the exception field from the JSON representation? Answer You can get the Error Attributes in your controller advice
Trying to learn Spring: BeanCreationException: Error creating bean with name
Started to learn “Spring in Action” and got a trouble on the very first chapter. I have simple Spring application, built with Maven: pom.xml <project …
How to re-create database before each test in Spring?
My Spring-Boot-Mvc-Web application has the following database configuration in application.properties file: spring.datasource.url=jdbc:h2:tcp://localhost/~/pdk spring.datasource.username=sa spring….
Spring Boot classpath
In the Spring Boot’s docs here, about serving static content, it says: By default Spring Boot will serve static content from a directory called /static (or /public or /resources or /META-INF/resources) in the classpath. I found that all the content in the directory: will be copied inside the classpath, so I can put my static content in: and all will
spring combine two validation annotations in one
I’m using Spring+Hibernate+Spring-MVC. I want to define a custom constraint combining two other predefined validation annotations: @NotNull @Size like this: and I want to use this annotation in my form models. UserController.java But it does not work. It accepts the less than 4 character passwords. How can I solve this problem? Answer This is a bit late, but technique of
Spring – No EntityManager with actual transaction available for current thread – cannot reliably process ‘persist’ call
I get this error when trying to invoke “persist” method to save entity model to database in my Spring MVC web application. Can’t really find any post or page in internet that can relate to this …
Spring web mvc example, boot, Error creating bean with name ‘jacksonObjectMapperBuilder’
I’m new to Spring and largely to Java beyond the language itself…minimal console apps, etc. I’m trying to get the Spring website example here (https://spring.io/guides/gs/serving-web-content/) to …
Not supported for DML operations with JPA update query
This has been asked once before but the solution did not solve the issue. I am creating a JUnit test: The query the above test is calling is: Error: Answer The @Modifying annotation must be placed on the updateMaterialInventory method, along to the @Query annotation, to let Spring-data know that the query is not a query used to select values,
Spring Rest Controller Return Specific Fields
I’ve been going through my head the best way to design a JSON API using Spring MVC. As we all know IO is expensive, and thus I don’t want to make the client make several API calls to get what they need. However at the same time I don’t necessarily want to return the kitchen sink. As an example I