My Retrofit 2 (2.0.2 currently) client needs to add custom headers to requests. I’m using an Interceptor to add these headers to all requests: Some headers I always want to add, but some headers I only need to add based on requirements of that specific endpoint, for example whether the user needs to be authenticated or not. I’d like to
Tag: annotations
What will happen if we interchange @service and @repository annotation in the spring MVC
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
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
How to write an Aspect pointcut based on an annotated parameter
I’m having a bit of trouble working out how to create a pointcut that will operate on beans that have a specific annotated parameter. My eventual aim is to validate the value of the parameter before it’s processed, but for the moment I just need to create the pointcut. Consider the following annotation I’d then like to apply this to
Spring MVC request and response flow explanation
I can’t find correct client request flow in below syntax.Could someone please clarify what is happening here? If possible please specify what are the corresponding spring classes/interfaces used in spring MVC process. Answer Request will be received by DispatcherServlet. DispatcherServlet will take the help of HandlerMapping and get to know the @Controller class name associated with the given request. So
Hibernate mapping between PostgreSQL enum and Java enum
Background Spring 3.x, JPA 2.0, Hibernate 4.x, Postgresql 9.x. Working on a Hibernate mapped class with an enum property that I want to map to a Postgresql enum. Problem Querying with a where clause on the enum column throws an exception. Code (heavily simplified) SQL: Hibernate mapped class: Java that calls the query: Hibernate xml query: Troubleshooting Querying by id
intellij incorrectly saying no beans of type found for autowired repository
I have created a simple unit test but IntelliJ is incorrectly highlighting it red. marking it as an error No beans? As you can see below it passes the test? So it must be Autowired? Answer I had this same issue when creating a Spring Boot application using their @SpringBootApplication annotation. This annotation represents @Configuration, @EnableAutoConfiguration and @ComponentScan according to
How to map Hibernate entity fields using camelCase to snake_case (underscore) database identifiers
I have database fields in underscore. I have entity fields in camelcase. I can’t change either of those. Is there something, maybe a class level annotation I can use to default entity column name annotations to the camelcase equivalent? for example, I have an entity like this: I dream of this: Answer You can use hibernate’s naming strategy. Such naming
Best practice for configuring Spring LdapTemplate via annotations instead of XML?
For a Spring Boot application, I successfully configured a Spring LdapTemplate using annotations, including the LdapContextSource dependency with @Values from application.properties. (Woot! I couldn’t find an example, so maybe this will help others.) The snippets (below) setup the context source, inject it into an LdapTemplate, and autowire that into my DirectoryService. Is there a better/cleaner way to setup the ContextSource
Override transactional method
I have method M with @Transactional in service A. I have service B extends A with overrided method M. Will be overrided method M still transactional? Or I should add there @Transactional? Answer What you are actually asking : is the @Transactional annotation on the method inherited. Short answer : no. Annotations on methods are never inherited. Long answer :