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
53
votes
2 answers

Benefits of JavaConfig over XML configurations in Spring?

Earlier the configurations used to be in hard coded in the code, later it was externalized to .property files (for sake of avoiding hard coded values, avoiding changing code for the sake of changing configurations..etc) then it moved to XML (for…
yathirigan
  • 5,619
  • 22
  • 66
  • 104
52
votes
2 answers

What is a Spring "stereotype"?

On a SpringSource blog entry, the following sentence references a stereotype. Because @Controller is a specialization of Spring's @Component Stereotype annotation, the class will automatically be detected by the Spring container as part of the…
chad
  • 7,369
  • 6
  • 37
  • 56
51
votes
2 answers

Difference between @EntityScan and @ComponentScan

I am trying to understand the difference here. I see that a class has been annotated with both of them with same package example : @Configuration @EntityScan("some.known.persistence") @ComponentScan({ "some.known.persistence"}) public class…
Raghuveer
  • 2,859
  • 7
  • 34
  • 66
50
votes
1 answer

Is it possible to set a bean name using annotations in Spring Framework?

I have a bean like this: @Bean public String myBean(){ return "My bean"; } I want to autowire it: @Autowired @Qualifier("myBean") public void setMyBean(String myBean){ this.myBean=myBean; } I need something…
Oleksandr
  • 3,574
  • 8
  • 41
  • 78
43
votes
5 answers

Difference between Spring annotations

Questions: 1) Difference between @Component and @Configuration? I have read that both remove the necessity of wiring code to be put in XML, but did not get the difference between these. 2) What are the differences between @Autowired, @Inject and…
Anand
  • 20,708
  • 48
  • 131
  • 198
39
votes
4 answers

Struts2 + Spring Security 2.06: Valuestack is null when attempting to use @Secured on an Action method

Before I begin, I've to say the closest answer I've found is here but honestly I don't really understand what's going on there. I'm using Struts2 + Spring Security 2.06 with a custom authentication provider and access decision manager to remove the…
shaunlim
  • 4,384
  • 6
  • 33
  • 38
38
votes
2 answers

Multiple DataSource and JdbcTemplate in Spring Boot (> 1.1.0)

I would like to inject a specific JdbcTemplatein a Spring Boot project. I tried to follow this example for multiple DataSourceconfiguration : http://spring.io/blog/2014/05/27/spring-boot-1-1-0-m2-available-now My code does compile and run, but only…
Xavier
  • 423
  • 1
  • 4
  • 8
37
votes
8 answers

Spring Boot @Value Properties

I have a Spring Boot application and in one of the classes, I try to reference a property from the application.properties file using @Value. But, the property does not get resolved. I have looked at similar posts and tried following the suggestions,…
user6641655
  • 523
  • 2
  • 8
  • 13
36
votes
6 answers

How to get error text in controller from BindingResult?

I have an controller that returns JSON. It takes a form, which validates itself via spring annotations. I can get FieldError list from BindingResult, but they don't contain the text that a JSP would display in the tag. How can I get…
Mike
  • 1,176
  • 3
  • 14
  • 26
36
votes
5 answers

Spring 4 - addResourceHandlers not resolving the static resources

My maven spring project directory structure is shown below. I am using Spring-4 annotation based configuration. I configure the resources like below. I tried many ways that are suggested in many Stackoverflow questions and other websites Spring 4…
vvra
  • 2,832
  • 5
  • 38
  • 82
36
votes
3 answers

Dynamically changing the @ResponseStatus in annotation driven Spring MVC

I am really not sure if this is feasible using Spring 3.2 MVC. My Controller has a method declared as below: @RequestMapping(method = RequestMethod.GET) @ResponseStatus(HttpStatus.OK) public @ResponseBody List getAll(){ return…
dharam
  • 7,882
  • 15
  • 65
  • 93
35
votes
6 answers

Can @PathVariable return null if it's not found?

Is it possible to make the @PathVariable to return null if the path variable is not in the url? Otherwise I need to make two handlers. One for /simple and another for /simple/{game}, but both do the same just if there is no game defined i pick first…
Rihards
  • 10,241
  • 14
  • 58
  • 78
33
votes
7 answers

@EnableTransactionManagement annotation with 2 transaction managers

I am using @Configuration annotation for configuration of spring instead of xml file. I am configuring 2 datasources with different session factory and different transaction managers. I am stuck with a problem here for @EnableTransactionManagement…
Mital Pritmani
  • 4,880
  • 8
  • 38
  • 39
33
votes
6 answers

Spring Security @PreAuthorization pass enums in directly

My question is a duplicate of Custom annotation with spring security but it went unanswered and I believe there should be a simple solution to the problem. Basically instead of…
user1751547
  • 2,211
  • 4
  • 21
  • 25
33
votes
4 answers

how to specify a bean as non lazy with annotations

Does anyone know how to specify a bean as non lazy when using annotations to configure the bean?
Michael Wiles
  • 20,902
  • 18
  • 71
  • 101
1
2
3
86 87