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

Spring annotations - @Configuration to invoke spring bean auto-building

If I declare a class using @Bean and then component scan for the class, spring will instantiate the class by invoking it's constructor and injecting constructor args and injecting any fields marked with @Inject. For simplicity's sake, lets call this…
lance-java
  • 25,497
  • 4
  • 59
  • 101
4
votes
2 answers

How to switch from many @RequestParam arguments to @ModelAttribute in a Spring Controller method

I' new to spring and i've managed to collect data from a form in a JSP view and to submit my form to a controller . From the data aquired from the view , i'm instantiating a model object , which also contains other model objects…
Adrian Bob
  • 741
  • 2
  • 12
  • 32
4
votes
1 answer

Why does Spring not inject @PersistenceContext entityManager when running on Tomcat vs standalone

I am trying to use Spring to inject @PersistenceContext entityManager into my service. The following configuration works standalone but does not work when deploying on Tomcat. When deploying on Tomcat, the entityManager remains null. My JPA configs…
Victor Lyuboslavsky
  • 9,882
  • 25
  • 87
  • 134
3
votes
3 answers

Spring MVC @AutoWired response not working

I have : @Controller @RequestMapping(value="admin/*", method=RequestMethod.GET) public class AdminController { @Autowired private HttpServletRequest request; @Autowired private HttpServletResponse response; @RequestMapping …
mjs
  • 21,431
  • 31
  • 118
  • 200
3
votes
1 answer

using @value with PropertyPlaceholderConfigurer

I have properties file report.properties (\WEB-INF\classes\properties\report.properties) with entry : reportTemplate = reports/report5.jrxml and applicationContext-reports.xml (\WEB-INF\config\applicationContext-reports.xml) with entry:
a Learner
  • 4,944
  • 10
  • 53
  • 89
3
votes
5 answers

Spring @Transactional doesn't work with other annotations?

So my Spring education continues. Currently I'm trying to learn some of the annotations and the things they bring to Spring 3. So I've got a mini webapp that can connect to a DB and put stuff in through a form and display records and so on.…
cardician
  • 2,451
  • 3
  • 26
  • 36
3
votes
3 answers

RequestMapping on presence of one of multiple parameters

I have a Spring3 controller in which I'm using the @RequestMapping annotation. I know I can use the params value to route based on the the presence or lack of a url parameter, but is there a way to route based on the presence of one of two…
Jkachins
  • 43
  • 1
  • 4
3
votes
2 answers

What is the difference between @Entity and @Document in spring boot?

Can you use both annotations on your database tables? id, just like some clarification on there differences. thank you
3
votes
2 answers

Why doesn't my @Cachable annotated method cache the result with EHCache?

I have an interceptor in Spring, which autowires two different services. Both services have methods that are tagged with @Cacheable from the ehcache-spring-annotations project, but with different cacheNames. public class MenuInterceptor extends…
Nicolai
  • 3,698
  • 3
  • 30
  • 34
3
votes
2 answers

apply custom validation annotation to parameter

I have the following classes used for validating a password. public class PasswordConstraintValidator implements ConstraintValidator { @Override public void initialize(ValidPassword constraintAnnotation) { } …
3
votes
3 answers

How to autowire a bean inside a Spring @Condition class

I have an interface IInterface.java like below: public interface IInterface { void printIt(); } And there are two implementation classes for this: ImplementationA.java and ImplementationB.java @Component public class ImplementationA implements…
DockYard
  • 989
  • 2
  • 12
  • 29
3
votes
0 answers

Does the use of @Configuration prevent auto-detection of @SpringBootConfiguration?

I've searched for the real meaning of using @TestConfiguration compared to @Configuration and I saw a statement in an official comment on @TestConfiguration. ...Unlike regular @Configuration classes the use of @TestConfiguration does not prevent…
3
votes
0 answers

Using annotation attributes in meta-annotations

I created the following annotation to only activate test methods, if the given file (of fileName attribute) exists in the data.scans.path directory (configured in Spring's application.yml): @Target({ElementType.TYPE,…
3
votes
2 answers

How to process custom annotation in Spring Boot with Kotlin?

CONTEXT: I would like to create a custom annotation in Spring Boot and add extra logic for processing. I give an example with rather simplistic annotation but I want to have several of such annotations with more fine-grained control. There are…
3
votes
1 answer

How to express array annotation argument in Kotlin?

When annotation has an array argument with basic type like String or Int it is straightforward how to use that: public @interface MyAnnotation{ String[] props(); } @MyAnnotation(props = ["A", "B", "C"]) class Foo {} Unfortunately that does not…
diziaq
  • 6,881
  • 16
  • 54
  • 96