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

Testing Spring @MVC annotations

I ran into a problem the other day where a @Valid annotation was accidentally removed from a controller class. Unfortunately, it didn't break any of our tests. None of our unit tests actually exercise the Spring AnnotationMethodHandlerAdapter…
Brandon Yarbrough
  • 37,021
  • 23
  • 116
  • 145
9
votes
2 answers

jetty 9 + JDK 8 + spring 4 Annotations

After upgrading to JDK 8 , the jetty 9 is no longer able to scan the spring annotations : I get the following error : MultiException[java.lang.RuntimeException: Error scanning file ApplicationInitializer.class, java.lang.RuntimeException: Error…
SurMan
  • 271
  • 10
  • 22
9
votes
2 answers

How do you override a spring bean defined in xml using Annotations?

I have an existing bean overrideBean defined in spring.xml which I would like to override using annotations. I have tried the following to override the bean: @Configuration @ImportResource({"/spring.xml"}) public class Main { public static…
William Hill
  • 186
  • 2
  • 8
8
votes
2 answers

Using Spring constructor injection with SonarQube

I have a piece of code with field injections I am trying to convert to use constructor injections instead. The initial code looks like this: @Autowired private Environment env; @Autowired private YYYAdaptor yyyAdaptor; @Autowired private…
Layman
  • 797
  • 1
  • 7
  • 23
8
votes
3 answers

what is the difference between @Bean annotation and @Component annotation at Spring?

It might be a very simple question for you.But I read lots of documents and I am totally confused.We can use @Component instead of @Bean or @Bean instead of @Component(as well as @Repository @Service @Controller) ? Cheers
Tonyukuk
  • 5,745
  • 7
  • 35
  • 63
8
votes
2 answers

Inject files as list of resources using wildcard by annotations in Spring

I have a class which I use as a spring bean. The bean is defined in the applicationContext.xml like: And MyClass looks…
8
votes
1 answer

Spring with embedded derby: hibernate dialect deprecation

I have a spring application configured with spring boot and config annotations. JPA configuration is: @Configuration @EnableTransactionManagement @EnableJpaRepositories public class JpaConfiguration { @Bean public DataSource dataSource() { …
guido
  • 18,864
  • 6
  • 70
  • 95
8
votes
2 answers

Multiple spring task executors with annotation-driven spring tasks

I have a class MessageProcessor being called by another method in another class (i.e. Caller). public class Caller { @Scheduled(filxedDelay=10) public void poll(){ //do stuff messageProcessor.process(msg); } } public class…
instanceOfObject
  • 2,936
  • 5
  • 49
  • 85
8
votes
1 answer

Inject a list of beans using Spring @Configuration annotation

I've got a Spring bean, and in the Spring Bean I have a dependency on a list of other beans. My question is: how can I inject a Generic list of beans as a dependency of that bean? For example, some code: public interface Color { } public class Red…
Erik Pragt
  • 13,513
  • 11
  • 58
  • 64
8
votes
3 answers

Autowiring not working in Spring 3.1.2, JUnit 4.10.0

Using Spring 3.1.2, JUnit 4.10.0, and pretty new to both versions. I'm having the problem that I can't get the annotation-based autowiring to work. Below are two samples, the one not using annotations, which is working fine. And the second one using…
Mathias Conradt
  • 28,420
  • 21
  • 138
  • 192
7
votes
1 answer

Spring Data JPA Immutable Entity

Using Spring Data JPA with Hibernate, are these two annotations interchangeable? org.hibernate.annotations.Immutable org.springframework.data.annotation.Immutable More specifically, can the Spring annotation replace the Hibernate annotation, to…
7
votes
2 answers

How to reference a bean by type in a SpEL?

The following is a minimal example, showing my problem. Main.kt: package com.mycompany.configurationpropertiestest import org.slf4j.LoggerFactory import org.springframework.boot.autoconfigure.SpringBootApplication import…
Tobias Hermann
  • 9,936
  • 6
  • 61
  • 134
7
votes
4 answers

@autowired annotation issue, not injecting bean in class, using Spring3.0, hibernate

following is my class: package com.abc.trade.util; public class StockTraderLogger { static Logger logger = Logger.getLogger("StockTraderLogger"); @Autowired ConfigService configService; public static void debug(Object…
Sagar
  • 1,242
  • 7
  • 22
  • 49
7
votes
3 answers

When to use Spring's @Repository annotation?

When reading about creating custom queries in Spring, I noticed that none of the classes (UserRepositoryCustom, UserRepositoryCustomImpl, UserRepository) use the @Repository annotation. I was surprised by this, because usually all the Spring…
Snackoverflow
  • 5,332
  • 7
  • 39
  • 69
7
votes
1 answer

How to create a custom annotation in spring boot?

i'm working on a spring project and i want to make annotation. I need something like the description below : @CustomAnnotation("b") public int a(int value) { return value; } public int b(int value) { return value + 1…
Djamel Kr
  • 759
  • 1
  • 4
  • 14