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
7
votes
3 answers

Difference between compile time & run time annotations of Spring

In a recent interview for a Java developer , I met with a question on spring annotation: What is the difference between compile time and runtime annotations in spring? Is there a concept like this? An answer would be appreciated.
Sam
  • 81
  • 1
  • 4
7
votes
2 answers

Custom WebArgumentResolver like @PathVariable

I would like to use a custom WebArgumentResolver for id -> entity. Easy enough if I use request parameters: use the parameter key to determine the entity type and look up accordingly. But I would like it to be like the @PathVariable annotation.…
dom farr
  • 4,041
  • 4
  • 32
  • 38
7
votes
2 answers

@PathVariable and @RequestParam not working together

I have below code in my controller: @RequestMapping(value = "/child/{nodeId}/{relType}",method = RequestMethod.GET, produces=MediaType.APPLICATION_JSON) public Iterable getConnectedNodes(@RequestParam("page")int page,…
7
votes
2 answers

Autowired Spring Beans across Java packages

I’m attempting to break my project up into three modules: core, admin and user so that I can share common code via core. The problem is that I can’t get Spring to pickup the autowired beans across different main packages, when I have everything in…
Clint
  • 327
  • 2
  • 14
7
votes
1 answer

@ActiveProfiles in meta annotation and on test class not working

I created a meta annotation @EmbeddedMongoDBUnitTest that activates two profiles to be used in spring based unit tests. The basic setup…
James
  • 11,654
  • 6
  • 52
  • 81
7
votes
1 answer

Spring MVC: Having multiple @ModelAttribute in form handling action

The context I have a simple association between two entities - Category and Email (NtoM). I'm trying to create web interface for browsing and managing them. To browse the category and to add e-mails into that category I use controller wrapped with…
Rafał Wrzeszcz
  • 1,996
  • 4
  • 23
  • 45
7
votes
3 answers

Spring custom annotation: how to inherit attributes?

I am creating my own custom shortcut annotation, as described in Spring Documentation: @Target({ElementType.METHOD, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Transactional(value = "Custom", readOnly = true) public @interface…
Laimoncijus
  • 8,615
  • 10
  • 58
  • 81
7
votes
1 answer

Understanding the use of @ModelAttribute and @RequestAttribute annotations in Spring MVC

I am pretty new in Spring MVC. Currently I am studying the Spring MVC Showcase, that demonstrates the features of the Spring MVC web framework. I have some problem to understand how Custom Resolvable Web Arguments are handled in this example. In…
AndreaNobili
  • 40,955
  • 107
  • 324
  • 596
7
votes
3 answers

How to test @Valid

In my entities I have some hibernate annotations for validation, like @NotEmpty, @Pattern.. and others In my controller, on save action, it has an @Valid parameter. But if any entity has any required field, and there is no annotation I will have…
Falci
  • 1,823
  • 4
  • 29
  • 54
7
votes
1 answer
7
votes
2 answers

How do you refactor a @Transactional method to split out non-transactional parts

I have a data access class which runs as part of a stand-alone java application. It is currently working which means that a transaction manager is defined but I want to refactor the class to reduce the scope of the transaction but if I do I get…
6
votes
1 answer

Spring MVC 3.1 without annotations?

I'm starting a new project with Spring 3.1, and have been eyeball deep in all the documentation and forum opinions about how to use the @Controller annotation. I personally dislike using annotations for MVC; I much prefer having all the URLs of a…
Stewart
  • 17,616
  • 8
  • 52
  • 80
6
votes
2 answers

Missing @XmlRootElement when creating a client from a wsdl

I have a question in regards to consuming a web service based on a third party wsdl file. I've taken the given wsdl and generated the 120+ java files required. This process was done by using xjc. Within the Sping environment, I was able to…
user310340
  • 61
  • 1
  • 1
  • 4
6
votes
2 answers

Convert Spring XML-based to Java-Based Configuration

I try not to using any xml.
xyzxyz442
  • 173
  • 3
  • 4
  • 11
6
votes
5 answers

How can I disable creating bean with @Component annotation in Spring?

I have some common interface for refactoring logic in my project. It looks about like this: public interface RefactorAwareEntryPoint { default boolean doRefactor() { if (EventLogService.wasEvent(getEventType())) { return…
Anton
  • 110
  • 1
  • 1
  • 7