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

not able to publish custom event in spring before context load

I am trying to publish a custom event in Spring MVC, but is is not firing while context is loading, below are the code snippet, The onConnectionOpened will be called after connecting to a server which is triggered after bean initialization using…
java_dev
  • 323
  • 6
  • 17
4
votes
2 answers

Custom annotation is not working on spring Beans

I have created my new custom annotation @MyCustomAnnotation @Target({ElementType.METHOD, ElementType.TYPE, ElementType.FIELD}) @Retention(RUNTIME) public @interface MyCustomAnnotation{ } I applied that annotation on component and bean. Here is the…
4
votes
1 answer

Is it possible to get the RequestMethod-verb in a custom PreAuthorize method?

I'm using a custom access checker with @PreAuthorize: @RestController @RequestMapping("/users") public class Users { @PreAuthorize("@customAccessChecker.hasAccessToMethod('USERS', 'GET')") @RequestMapping(method = RequestMethod.GET) …
4
votes
1 answer

Spring scheduled tasks: from XML to annotation

In our Spring web-application, we are moving from XML based configuration to Annotation based configuration. I'm stuck with a scheduled task defined with this XML
Stefaan Neyts
  • 2,054
  • 1
  • 16
  • 25
4
votes
1 answer

Spring @PropertySource value not overridding

In my sprint boot application, I have a configuration class to read property files: common.properties and dev.properties. I have the same key server.url in both the property files. The value is not overridden. As per the spring documentation, the…
Krishnanunni P V
  • 689
  • 5
  • 18
  • 32
4
votes
2 answers

Why do we need @Component spring annotation for Jersey resource in spring-boot-starter-jersey project?

This question is regarding the sample: https://github.com/spring-projects/spring-boot/blob/master/spring-boot-samples/spring-boot-sample-jersey/src/main/java/sample/jersey/Endpoint.java Why do we need "@Component" annotation for Jersey resource when…
Jothi
  • 511
  • 1
  • 5
  • 9
4
votes
1 answer

Multiple Spring @Transactional annotations in one application?

Within my application I have several @Transactional annotations on different methods. They use the Crud Repository to carry out deletes on my database. I am wondering at what stage do these deletes get carried out, and do I need all the…
java123999
  • 6,974
  • 36
  • 77
  • 121
4
votes
1 answer

Spring Framework AliasFor annotation dilema

I am using spring boot (1.3.4.RELEASE) and have a question regarding the new @AliasFor annotation introduced spring framework in 4.2 Consider the following…
CipQuestion
  • 391
  • 4
  • 11
4
votes
1 answer

Initialization map of beans using Spring JavaConfig

I have AbstractParent class with autowired variable field and Child class, that extends AbstractParent. In my application I need map of sub-classes of AbstractParent to implement strategy pattern. I init my application using Spring JavaConfig. Here…
4
votes
2 answers

What's wrong within the usage of BeanFactoryAnnotationUtils?

I'm trying to do simple call to the method BeanFactoryAnnotationUtils.qualifiedBeanOfType Here the pom.xml of the project :
Emilien
  • 106
  • 9
4
votes
0 answers

Write Unit Test for custom annotation?

I have a Java Spring method I want to test out that look something like this: @RunWithPermission(values={Permission.Manage, Permissions.ManageAll}, any=true) @RequestMapping(method = RequestMethod.POST) public Object createReport(@RequestBody…
user1871869
  • 3,317
  • 13
  • 56
  • 106
4
votes
2 answers

Spring and Quartz integration with Java Config

I searched a lot, but i couldn't fine any post or comment or any complete code on integrating spring and quartz and store the quartz config in database with java config (XML-LESS) could anyone help me and show me some code or reference ? thanks a…
hadi
  • 229
  • 1
  • 7
  • 16
4
votes
2 answers

How to make a property injection via @Value annotation mandatory?

I have the following Test.java POJO class being populated from a property file using the @ConfigurationProperties annotation. I have seen the usage of @Required annotation to make it a mandatory. Rather than defining annotations at the setter method…
yathirigan
  • 5,619
  • 22
  • 66
  • 104
4
votes
1 answer

spring-data-elasticsearch - @Field / FieldIndex.not_analyzed ignored

I am using spring-data-elasticsearch 1.1.2. I am trying to use java annotation to specify that a field should not be analyzed. I use the following annotation: @Field(index = FieldIndex.not_analyzed) private String category; The generated…
4
votes
1 answer

Custom property editors do not work for request parameters in Spring MVC?

I'm trying to create a multiaction web controller using Spring annotations. This controller will be responsible for adding and removing user profiles and preparing reference data for the jsp page. @Controller public class ManageProfilesController { …
dvd
  • 2,296
  • 1
  • 15
  • 11