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
13
votes
1 answer

Spel not supported on spring annotation @Scheduled.fixedDelayString

I want to configure the fixedDelay in seconds in my properties file, then I want to convert it to millis in @Scheduled annotation. I expected this to work: @Scheduled(fixedDelayString = "#{${my.scheduler.fixed.delay} * 1000}") But it throw this…
amgohan
  • 1,358
  • 3
  • 14
  • 24
13
votes
1 answer

Why in Spring I am not allowed to annotate a final class with @Configuration?

I am studying for the Spring Core certification and I have some doubts related to the answer of this question founded on the study material stuff. Why are you not allowed to annotate a final class with @Configuration My reasoning is the following…
AndreaNobili
  • 40,955
  • 107
  • 324
  • 596
13
votes
4 answers

Spring - Path variable truncate after dot - annotation

I am trying to set up a REST endpoint that allows querying a user by their email address. The email address is the last portion of the path so Spring is treating foo@example.com as the value foo@example and truncating the extension .com. I found a…
troymass
  • 1,022
  • 3
  • 11
  • 24
13
votes
2 answers

What happens in Spring if I use the @ActiveProfiles annotation on a configuration class instead use it on the class that defines my beans?

I am studying for the Spring Core certification and I have some doubts related to the use of profiles into JUnit tests. So I know that if I annote a class in the following way: @Profile("stub") @Repository public class StubAccountRepository…
AndreaNobili
  • 40,955
  • 107
  • 324
  • 596
13
votes
1 answer

How to configure component-scan by annotation only in Spring?

I'm running a war file on a tomcat webserver environment. I have an annotation based config for @Beans, and a xml config for webservices: @Configuration //@ComponentScan(basePackageClasses = ...) public class AppConfig { //beans…
membersound
  • 81,582
  • 193
  • 585
  • 1,120
13
votes
2 answers

How to retrieve JNDI using Spring @Configuration instead of XML configuration

I've started development of a new Spring 3.2.4 application and am trying to use Java based configuration instead of XML files as I have used in the past. However, I am having trouble making the transition. Using XML, I would code it as…
Eric B.
  • 23,425
  • 50
  • 169
  • 316
13
votes
2 answers

spring annotation-based configuration - memory consumption too high?

As I noticed crazy high RAM usage on my client application (Swing-based), I started looking into it and it seems like this is somehow related to Annotation-based configuration in Spring. As you will see in my edits below, i realized that this occurs…
Mario B
  • 2,102
  • 2
  • 29
  • 41
12
votes
0 answers

Pass value from a Spring meta-annotation to another annotation

My use case: I will have a lot of @PreAuthorize annotation in the form @PreAuthorize("hasAuthority('RESPECT_MY_AUTHORITY')"). I'd like to create a meta-annotation @HasAuthority which takes the authority as a value and pass it to…
grandouassou
  • 2,500
  • 3
  • 25
  • 60
12
votes
2 answers

What is the proper way to activate @PostConstruct via CommonAnnotationBeanPostProcessor by Java configuration?

I'm using Spring 4 with SpringBoot and Spring-Web with Java configuration. To have my @PostConstruct annotated methods executed by Spring at launch, it is necessary to register CommonAnnotationBeanPostProcessor with the context, otherwise…
zkn
  • 121
  • 1
  • 1
  • 4
12
votes
3 answers

Spring validation @AssertTrue

How do I display on a view jsp validation error message that occurs as a result of @AssertTrue annotation? It isn't tied to a specific field, but I am using it to validate a combination of fields. If I use that will display…
Eqbal
  • 4,722
  • 12
  • 38
  • 47
12
votes
5 answers

How to declare a Spring bean autowire-candidate="false" when using annotations?

I am using @ComponentScan and @Component to define my spring beans. What I would like is to declare one of these beans to be autowire-candidate=false. This could be done with this attribute in xml. Isn't there the equivalent in annotations? The…
Nazaret K.
  • 3,409
  • 6
  • 22
  • 31
12
votes
3 answers

Spring 4.1 @JmsListener configuration

I would like to use the new annotations and features provided in Spring 4.1 for an application that needs a JMS listener. I've carefully read the notes in the Spring 4.1 JMS improvements post but I continue to miss the relationship between…
TemarV
  • 317
  • 1
  • 4
  • 12
12
votes
2 answers

Spring annotations @ModelAttribute and @Valid

What are the advantages of using @ModelAttribute and @Valid? Which are the differences? Is it possible to use them together?
vdenotaris
  • 13,297
  • 26
  • 81
  • 132
12
votes
2 answers

result of over-eager type matching - consider using 'getBeanNamesOfType' with the 'allowEagerInit' flag turned off

org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'org.springframework.cache.annotation.AnnotationCacheOperationSource#0': Bean with…
skd
  • 129
  • 1
  • 2
  • 7
11
votes
3 answers

How to add a custom annotation to Spring MVC?

Can anyone explain what I need to do to implement my own annotation that would add functionality to my web requests? For example: @Controller public class MyController { @RequestMapping("/abc") @RequiresSomeSpecialHandling public void…
rustyx
  • 80,671
  • 25
  • 200
  • 267