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

Error creating bean with name 'resourceHandlerMapping'

I have an application with spring that use a JpaConfiguration class to deal with my database, and a WebAppMvcConfigurer class to deal with the front via json message. Both have an @Configuration and are in the same package. I have an App class in a…
Brice B
  • 103
  • 1
  • 1
  • 8
6
votes
2 answers

@Async not working for method having return type void

I wanted to make a method writing to DB as async using @Async annotation. I marked the class with the annotation @EnableAsync: @EnableAsync public class FacialRecognitionAsyncImpl { @Async public void populateDataInPushQueue(int mediaId,…
6
votes
1 answer

What is the correct use of the property map read from .yaml with @Value Spring Annotation

I have injected properties from the map read from some .yaml in Spring Boot application the following way: @Value("#{${app.map}}") private Map indexesMap = new HashMap<>(); But neither app: map: {Countries: 'countries.xlsx',…
6
votes
1 answer

@AutoConfigureAfter not working as desired

I have 3 spring-boot-starter projects One of the autoconfiguration class has the following code: @Configuration @ConditionalOnClass(value = Config.class) @AutoConfigureAfter(value = {FileGeneratorConfig.class, FileUploaderConfig.class}) public class…
sachin jain
  • 224
  • 1
  • 4
  • 16
6
votes
2 answers

NoUniqueBeanDefinitionException in Spring annotation driven configuration

I am getting the following error when trying to autowire two beans using No qualifying bean of type [javax.jms.ConnectionFactory] is defined: expected single matching bean but found 2: aConnectionFactory,…
karruma
  • 768
  • 1
  • 12
  • 32
6
votes
5 answers

Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping'

Use jdk 1.8 SpringMVC-4.3.3 SpringCore-4.3.3 javax.servlet-api-3.0.1 spring-data-jpa:1.10.4 hibernate-entitymanager:4.2.5.Final hibernate-core:4.2.5.Final Simple Logging Facade for Java:1.6.1 I encountered with such…
kopylov
  • 1,281
  • 3
  • 9
  • 12
6
votes
2 answers

Are there anyway to disable annotation in spring4?

I have a question, maybe simple, but I can not find out the solution. I am using spring boot and added some annotation to the code like this: @EnableEurekaClient @SpringBootApplication @EnableCaching public class MyApplication { public static…
user3006967
  • 3,291
  • 10
  • 47
  • 72
6
votes
2 answers

Spring aliasFor for Annotations with Target(PARAMETER)

I am trying to use the Meta-annotation of spring using the aliasFor annotation to create a custom annotation for the springs RequestParam Simply 'extend/replace' @Target(ElementType.PARAMETER) @Retention(RetentionPolicy.RUNTIME) @Documented public…
lawal
  • 952
  • 10
  • 19
6
votes
1 answer

Annotations for feature flipping REST end points

I have spring controller with several (REST) endpoints. I want to bring up multiple instances of this controller where each instance would have few endpoints selectively enabled/disabled. Based on my reading so far, togglz provides feature…
mobileDev
  • 1,358
  • 2
  • 14
  • 34
6
votes
1 answer

Tuckey URL Rewrite Filter Java Class Configuration

I have been researching how to perform URL rewrites on Tomcat 8 and keep running into the same two suggestions. 1) Use Tuckey URLRewriteFilter. 2) Run Apache on top of Tomcat to use mod_rewrite. In regards to the former, URLRewriteFilter doesn't…
6
votes
2 answers

How to set hibernate.hbm2ddl.auto in Spring with Annotations and pure Java

How would one go about setting up the following in Spring using only Java and annotations. I amIt should be possible and I do believe it is a lot cleaner to make projects xml free. PS: This…
SARose
  • 3,558
  • 5
  • 39
  • 49
6
votes
2 answers

Failed to load ApplicationContext when I use ContextConfiguration annotation

I have following class header: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "classpath:WEB-INF/applicationContext.xml") public class OwnerTerminalsControllerTest and following project structure: When I run application…
gstackoverflow
  • 36,709
  • 117
  • 359
  • 710
6
votes
2 answers

When do we use denyAll in spring security

I am a bit confused as to why someone would use @PreAuthorize("denyAll") for a method. As per the spring security documentation, it always evaluates to false. If we are not going to allow access to a particular method, what is the point of keeping…
Zack
  • 2,078
  • 10
  • 33
  • 58
6
votes
0 answers

Make other components aware of @WebIntegrationTest random port

I've been playing around with Spring boot these last days, and I really like the @WebIntegrationTest annotation, that allows to startup a Tomcat and deploy a Spring boot app in it automatically. It gives the option of starting Tomcat on a random…
Vincent F
  • 6,523
  • 7
  • 37
  • 79
6
votes
1 answer

what is the order of bean loading if I have multiple configuration files in spring?

I have three configuration files in spring application. @Configuration public class FooConfig { ... } @Configuration public class BarConfig { ... } @Configuration public class FooBarConfig { ... } what is the order in which the beans are loaded?…
brain storm
  • 30,124
  • 69
  • 225
  • 393