Questions tagged [spring-annotations]

A common placeholder for issues related to the use of annotations with the Spring framework

The Spring Framework () provides several annotation-driven configuration options from wiring beans to managing transaction.

Annotation types

JSR support

  • JSR 107
    • @CacheResult
    • @CachePut
    • @CacheRemove
    • @CacheRemoveAll
    • @CacheDefaults
    • @CacheKey
    • @CacheValue
  • JSR 250:
    • @Resource
  • JSR 303:
    • @Valid
    • @NotNull
    • @Size, etc
  • JSR 330:
    • @Inject
    • @Named

Useful links

1301 questions
22
votes
3 answers

What is "persistence exception translation" for @Repository beans

I was reading Spring with annotation part and I came across @Repositoryannotation I read that @Repository beans differ from @Component beans in the sense that they are eligible for persistence exception translation. Can somebody please elaborate…
Anand
  • 20,708
  • 48
  • 131
  • 198
22
votes
3 answers

applicationContext not finding Controllers for Servlet context

I have a Spring web app with an applicationContext.xml and a dispatcher-servlet.xml configuration. I've defined the in applicationContext.xml, but when I run my app the Controllers are not found unless I also add…
acvcu
  • 2,476
  • 10
  • 40
  • 56
22
votes
2 answers

Meaning of Spring @ManagerResource: persistPolicy, persistPeriod, persistLocation and currencyTimeLimit

What does the following fields mean in Spring @ManagedResource used for JMX? There is no Javadoc or related description in Spring documentation. 1. String persistPolicy() default ""; 2. int persistPeriod() default -1; 3. String…
Mohsen
  • 3,512
  • 3
  • 38
  • 66
21
votes
1 answer

Maven: package io.swagger.annotations does not exist

I want to document my project with swagger. I add swagger annotations and io.springfox dependencies to my project but when I run mvn clean package I have a lot of errors: PS D:\parent-project> mvn clean package [INFO] Scanning for projects... [INFO]…
Sotnas
  • 213
  • 1
  • 2
  • 5
21
votes
5 answers

Spring 3 MVC - form:errors not showing the errors

I am using annotation based validation but for one of the forms I am not able to show any errors using the form:errors tag. When I debug the method, I can see the BindingResult has errors, but for some reason its not being displayed on the form. I…
Eqbal
  • 4,722
  • 12
  • 38
  • 47
20
votes
3 answers

Spring Boot : Custom Validation in Request Params

I want to validate one of the request parameters in my controller . The request parameter should be from one of the list of given values , if not , an error should be thrown . In the below code , I want the request param orderBy to be from the list…
20
votes
3 answers

Is it possible to use @Resource on a constructor?

I was wondering if it possible to use the @Resource annotation on a constructor. My use case is that I want to wire a final field called bar. public class Foo implements FooBar { private final Bar bar; …
Marco
  • 15,101
  • 33
  • 107
  • 174
20
votes
1 answer

Can you specify multiple @Conditional annotations?

With Spring Boot, can one use multiple @Conditional annotations on one @Bean definition? If so, is there a predictable order that they are resolved? In other words, can I specify both @ConditionalOnResource and @ConditionalOnMissingBean on the same…
Justin Miller
  • 757
  • 2
  • 8
  • 19
19
votes
3 answers

How do @PostFilter and @PreFilter work in Spring Security?

Being new to Spring's security annotations, I need a clarification for the below code. @PostFilter("hasPermission(filterObject, 'READ') or hasRole('ROLE_ADMIN')") public List getUsers(String orderByInsertionDate, Integer…
Zack
  • 2,078
  • 10
  • 33
  • 58
19
votes
9 answers

@Autowired - No qualifying bean of type found for dependency at least 1 bean

Currently I'm facing an issue in Autowire configuration between controller and the service layer. I'm unable to trace my mistakes. Simple Log Info SEVERE: Exception while loading the app SEVERE: Undeployment failed for context /OTT …
Arun
  • 1,010
  • 6
  • 18
  • 37
18
votes
5 answers

Is it possible to guarantee the order in which @PostConstruct methods are invoked?

I have a system which is using Spring for dependency injection. I use annotation-based autowiring. The beans are discovered by component scanning, i.e. my context XML contains this: I have…
wool.in.silver
  • 547
  • 1
  • 3
  • 13
18
votes
4 answers

Spring Boot : Spring always assigns default value to property despite of it being present in .properties file

I am working with Spring boot 1.1.8 which uses Spring 4.0.7. I am autowiring the properties in my classes with @Value annotation. I want to have a default value if the property is not present in properties file so, I use ":" to assign default value.…
Darshan Mehta
  • 30,102
  • 11
  • 68
  • 102
18
votes
3 answers

Optional @PropertySource location

I'm using Spring 3.2 in a web application and I'd like to have a .properties file within the classpath which contains default values. The user should be able to use JNDI to define a location where another .properties is stored which overrides the…
Gerhard Schlager
  • 3,155
  • 1
  • 31
  • 53
18
votes
3 answers

can anybody explain me difference between class level controller and method level controller..?

I am new to spring framework....while searching on google..I found few examples which has @RequestMapping annoted at the class level and few examples showing it at menthod level When to use class level RequestMapping and menthod level RequestMapping…
JOHND
  • 2,597
  • 6
  • 27
  • 35
17
votes
1 answer

Error creating bean with name 'org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0' defined in ServletContext resource

PROBLEM : I am creating a pointcut for execution of a method in a class . This class is a controller class and denoted by annotation @Controller and hence no bean is needed for the same which is required by the aspect. I am attaching the dispathcher…
user548656
  • 173
  • 1
  • 1
  • 5