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

Spring + TestNG integration tests, injecting DAO with annotations fails

I first did not mention what was the key component of this issue: I am using TestNG here. I have a DAO layer performing persistence. It works fine as part of my little web app (I have a classic Controller, Service, DAO layers design). I can update…
Adriano
  • 19,463
  • 19
  • 103
  • 140
5
votes
2 answers

@Value annotations in base test class not injecting values from properties file

For some reason, @Value annotations are not being injected into my class that I'm using as a base for other test classes. I'm new to Spring and my knowledge of Java isn't the best yet. I'm sure this will be much more obvious to someone with more…
Luke
  • 768
  • 2
  • 14
  • 33
5
votes
2 answers

In Spring 3.1 can be used in conjunction with @Configuration

I am migration from Spring 3.0.5 to 3.1 since I need to have custom RequestMappingHandlerMapping. I am facing problems in plug-in of extended RequestMappingHandlerMapping - I had existing servlet-conetxt.xml and I added WebConfig with @Configuration…
4
votes
2 answers

What is the best way to implement authorization/access control in a Spring 3 MVC web application?

Buddies, I'm about to develop a web application using Spring 3 MVC as web framework, Hibernate Annotations as ORM framework However, I'm facing a problem to design a good database based access control for this application. In my work we are used to…
4
votes
2 answers

How to create custom @ConditionalOnProperty for simpler usage?

In a Spring-Boot project, I use @ConditionalOnProperty to choose whether some Beans get loaded or not. It looks like the following: @ConditionalOnProperty( prefix = "myservice", name = "implversion", havingValue = "a" ) @Service public…
AdrienW
  • 3,092
  • 6
  • 29
  • 59
4
votes
1 answer

In springboot, how to rename Form-data fields while mapping using @ModelAttribute?

I am working with spring-boot, in my controller, I am receiving a formData. I'm mapping the request to the POJO using the @ModelAttribute however, the formData names are not uniform. In this case, @JsonProperty is not helping. I was looking for some…
Stalwart
  • 53
  • 4
4
votes
1 answer

Does @Async ever work without @EnableAsync

I am new to Java and working on an existing Spring MVC application. The project has a controller where many endponts are decorated with @Async annotation. But nowhere in the project did I find @EnableAsync annotation.I know @EnableAsync should be…
4
votes
2 answers

Spring possibility to @Value on a Pojo / object

Small question regarding the spring annotation @Value please. This annotation is powerful, well known and offers the possibility out of the box to bind types such as boolean, String, and even more complex data structures such as List, Map
PatPanda
  • 3,644
  • 9
  • 58
  • 154
4
votes
1 answer

Using @Conditional Spring annotation without knowing the whole property name

I want to optionally enable a @Configuration, based on whether a type of application.properties property exists or not. However I will not know the whole property name in advance, only part of its prefix…
PentaKon
  • 4,139
  • 5
  • 43
  • 80
4
votes
1 answer

Spring Boot @Async use With @PostConstruct

Edit for Solution This ended up being my @Service class with multi-threading working. It populates each table in the DB at the same time. No longer needed the @Async annotations or task executor with this solution. @Service public class AsyncDBLoad…
Brady Haden
  • 225
  • 4
  • 13
4
votes
2 answers

What's the difference between @Lazy annotation and lazy-init attribute of tag?

As per my understanding, @Lazy annotation and lazy-init attribute of tag should have the same functionality. But when I developed the following code, it's showing distinct behaviours. In the following code, I was expecting :- (Circular Dependency…
4
votes
3 answers

Spring RequestBody with Postman testing

I am testing my application and i found something weird. My code: @RequestMapping(value = "/test/{subscriberId}", method = RequestMethod.PATCH, consumes = "application/json", produces = "application/json") public void test(@PathVariable final…
theodosis
  • 79
  • 1
  • 1
  • 13
4
votes
2 answers

Restricting @PropertySource to specific @Configuration classes in spring

I have the following property files: application.properties - Base spring config common.properties - Common config servicea.properties - Service specific config password.properties - Password Config Based on the last three files, I have 3…
shadoweye14
  • 773
  • 2
  • 7
  • 22
4
votes
2 answers

Spring AOP - annotation with args

I am stuck with a problem in spring boot. I am trying to give extra functionality to some RestControllers, and I am trying to achieve it with some custom annotations. Here is an example. My…
Balint Toth
  • 41
  • 1
  • 3
4
votes
1 answer

error Type referred to is not an annotation type: MyAnnotation

I am following the given documentation at Custom Spring AOP Annotation Following are sources I have written in my project with similar dependencies as mentioned in the article. Annotation Definition: package com.sell.annotations; import…
Jaraws
  • 581
  • 1
  • 7
  • 24