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
11
votes
4 answers

Spring 3.0.6 MVC @PathVariable and @RequestParam blank/empty in JSP view

I have been trying to get an incredibly simple controller/view set up, and just can't make it work. In my web.xml, I've defined a called servlet-context.xml, which is running ok. In servlet-context.xml, I've set:
alexmuller
  • 2,207
  • 3
  • 23
  • 36
11
votes
2 answers

@ControllerAdvice overrides exception @ResponseStatus

I'm not sure why but the @ControllerAdvice is overriding the response code defined at Exception level using the @ResponseStatus annotation. Exception: @ResponseStatus(HttpStatus.BAD_REQUEST) public class GreetException extends RuntimeException…
mvlupan
  • 3,536
  • 3
  • 22
  • 35
11
votes
3 answers

DLS_DEAD_LOCAL_STORE SuppressWarnings FindBugs false positive

I'm trying to eliminate a false positive for DLS_DEAD_LOCAL_STORE Here's what I have tried so far: @SuppressWarnings("DLS_DEAD_LOCAL_STORE") @edu.umd.cs.findbugs.annotations.SuppressWarnings("DLS_DEAD_LOCAL_STORE") (based on SuppressWarnings not…
Garfield
  • 1,247
  • 4
  • 15
  • 33
10
votes
1 answer

Specifying @CrossOrigin orgins via an environment variable

Is it possible to specify the origins for the @CrossOrigin Annotation via an environment variable? I want to do this so that I can use the same code base for uat/staging/production. I want my uat/staging environments to be accessible via localhost…
Jags
  • 1,639
  • 1
  • 16
  • 30
10
votes
1 answer

@PropertySource with absolute path to avoid "java.io.FileNotFoundException: Could not open ServletContext resource"

My application gets the location of a properties file from an environment variable, and it may not be in the WEB-INF folder. I'm getting file not found, but this file definitely exists already. I don't want to use the classpath: prefix, and I…
Alexander Taylor
  • 16,574
  • 14
  • 62
  • 83
10
votes
2 answers

Spring MVC - HTTP status code 400 (Bad Request) for missing field which is defined as being not required

I have Spring MVC application with this controller method. @RequestMapping(value = "/add", method = RequestMethod.POST) public String addNumber(@RequestParam(value="number", required=false) Long number) { ... return "redirect:/showAll/"; } In…
AlexLiesenfeld
  • 2,872
  • 7
  • 36
  • 57
9
votes
2 answers

Is there a way in Spring to autowire all dependencies of a given type?

I'm using annotations-based wiring (ie @Configurable(autowire=Autowire.BY_TYPE)) for a given class, and I'd like to wire all beans of a given type into it as a list: application context:
Naftuli Kay
  • 87,710
  • 93
  • 269
  • 411
9
votes
1 answer

Why EntityScan , EnableJpaRepositories annotations required if we are already using componentScan annotation?

I am already using ComponentScan annotation in Main class of Spring Boot app , but If I use only this annotation it will gives issue while getting repositories reference. So to overcome this I am using EntityScan and EnableJpaRepositories…
OnkarG
  • 267
  • 1
  • 3
  • 16
9
votes
1 answer

SpEL used in @Document indexName with spring data elasticsearch and spring boot is not being parsed

looking for some help using the SpEL inside @Document annotation in reference to: spring-data-elasticsearch:3.2.3.RELEASE and spring boot 2.2.1 RELEASE i am having trouble googling for help with this problem as the keywords pick up unrelated…
9
votes
1 answer

What is the difference between @RequestMapping and @PostMapping

in the below example, I am trying to undersatnd the difference between @RequestMapping and @PostMapping. For @RequestMapping: when i do the POST request: http://localhost:8085/call1/initparam1?val=1111 via postman, it executes correctly. but…
Amrmsmb
  • 1
  • 27
  • 104
  • 226
9
votes
5 answers

Spring boot Persistence Context annotation

I am new in Spring Boot and trying to create a basic REST example in Spring boot. I am taking help from Spring Boot REST example website to create a basic example. Most of the things are clear to me but I am stuck with one annotation which is being…
Priyanka Singh
  • 91
  • 1
  • 1
  • 2
9
votes
1 answer

Spring ComponentScan excludeFilters annotation not working in Spring Boot Test context

I am using Spring Boot 1.4.3.RELEASE and want to exclude some components from being scanned when running the tests. @RunWith(SpringRunner.class) @SpringBootTest @ComponentScan( basePackages = {"com.foobar"}, excludeFilters = …
Javide
  • 2,477
  • 5
  • 45
  • 61
9
votes
3 answers

Spring security 4 @PreAuthorize(hasAuthority()) access denied

I am trying to convert a Spring Security 3 @Secured("admin") annotation into Spring Security 4 compatible fashion. This is my usersService.java @PreAuthorize("hasAuthority('admin')") public List getAllUsers() { return…
ericcire
  • 313
  • 1
  • 6
  • 12
9
votes
2 answers

Using Spring Dynamic Languages Support from Groovy Configuration

I'd like to use Dynamic Languages Support of Spring Framework, to create a reloadable bean (at runtime!) from a Groovy script. I want to avoid xml configuration, and use annotations (or similar) within a Spring Boot Application context. This is an…
Nick Grealy
  • 24,216
  • 9
  • 104
  • 119
9
votes
5 answers

Spring autowired bean causes null pointer

I have a logger class that makes use of a service. Each time a new logger is created, I expect to have access to the singleton scoped logging service. I autowire the logging service into the logger however, a null pointer exception is returned. I…
robinjohnobrien
  • 1,092
  • 2
  • 11
  • 19