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
0 answers

How to access method annotations on spring controller from OncePerRequestFilter

In a OncePerRequestFilter (method doFilterInternal), i'd like to access info about controller method (and ideally the controller itself too) that will eventually be run. Specifically, I'm looking for annotations that are on that method. Is there a…
bdwain
  • 1,665
  • 16
  • 35
6
votes
1 answer

Autowiring custom-made Spring component in Grails

I have a custom-made Spring which is bundled in a jar, which is then set as a dependency to my Grails app. I load the app-context for the bean with importBeans statement in resoueces.groovy like beans = { …
kaskelotti
  • 4,709
  • 9
  • 45
  • 72
6
votes
2 answers

Java Spring Framework jmx managed annotation @ManagedAttribute not showing method in MBeanServerConnection/Jconsole/Visual vm/bean list

Ive Added Spring annotation's to my code but when connecting via visual vm the method "myExample()" isn't showing in the JMX bean list My code : import org.springframework.beans.factory.annotation.Autowired; import…
Nimrod007
  • 9,825
  • 8
  • 48
  • 71
6
votes
1 answer

Spring/REST Application with HOT Deployment: Groovy script does not load dynamically from applicationContext.xml on tomcat startup at runtime

I am in the process of converting an already exisiting Java Web application into a RESTful web application using Spring MVC and Groovy. One of the main features I wanted to achieve was HOT DEPLOYMENT. I chose groovy because I did not want to make…
6
votes
2 answers

How can the Spring Environment be injected properly in one method but not another?

neo4jDatabase() is fine but environment is always null in graphDatabaseService()... how/why? @Configuration @PropertySource("classpath:/neo4j.properties") @EnableNeo4jRepositories("reservation.repository.neo4j") public class Neo4jConfig extends…
chrisjleu
  • 4,329
  • 7
  • 42
  • 55
6
votes
2 answers

Spring and Spring security configuration help, cannot find a bean

I keep receiving the exception with a message: "org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'userDetailsService' is defined" even though the bean is defined as a service in the UserDetailsServiceImpl class. Such…
user724535
  • 513
  • 1
  • 8
  • 18
5
votes
2 answers

Difference between @Entity and @Table in Spring boot . Do we need both?

Do we need both annonation for a model class? What is the difference between @Entity and @Table @Entity @Table(name = "widget") // do we need this?? public class WidgetEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private…
Mustafa
  • 1,738
  • 2
  • 24
  • 34
5
votes
3 answers

VSCode, Gradle, Spring Boot, Can't import javax.validation

All. I want to use @Valid and @NotEmpty in the spring boot(2.3.0) framework. But I was unable to import javax.validation so I couldn't. Here is the screen and build.gradle file I am currently experiencing: Can't be used @Valid annotation Can't be…
Changjoo Sohn
  • 53
  • 1
  • 4
5
votes
2 answers

Spring custom @Enable annotation meta-annotated with @ComponentScan

I'm trying to write my own @Enable annotation for Spring framework, which should be used as follows: package com.example.package.app; @SpringBootApplication @com.example.annotations.EnableCustom("com.example.package.custom") public class…
knittl
  • 246,190
  • 53
  • 318
  • 364
5
votes
3 answers

Why Spring Boot is not finding a @Service bean trying to perform autowiring? the bean exist but it can't find it

I am experiencing a strange problem working on a Spring Boot 2.2.5.RELEASE project that uses JUnit. I try to explain my problem in details: 1) I defined a service. First I defined an interface named OrderService, like this: package…
AndreaNobili
  • 40,955
  • 107
  • 324
  • 596
5
votes
4 answers

Slight Difference between @RestController & @Component

Although every page on internet says that @RestController is a specification of @Component.I dont know whether it has to be related with DispatcherServlet. But when I try below code by switching between @RestController & @Component, I don't see same…
ASharma7
  • 726
  • 3
  • 8
  • 27
5
votes
2 answers

How to detect if @Cacheable method output comes from cache?

There is a method annotated with @Cacheable that returns an object: @Service public class UserService { @Cacheable("userData") public UserData getUserData(String userName) { UserData userData = new UserData(); …
Politechniczny
  • 453
  • 3
  • 13
5
votes
0 answers

When is it safe to depend on Spring's @PreDestroy?

Per Spring's documentation here, I added a shutdown hook: SpringApplication app = new SpringApplication(App.class); DefaultProfileUtil.addDefaultProfile(app); appContext = app.run(args); appContext.registerShutdownHook(); However the @PreDestroy…
user3338098
  • 907
  • 1
  • 17
  • 38
5
votes
4 answers

Spring MVC Annotations

I've been over Spring's documentation a couple times, but I don't seem to be able to get @Controller, etc annotations to work. I am loading the dependencies and repositories in my POM (... are my specific values):
mathlovingkitten
  • 168
  • 1
  • 3
  • 9
5
votes
1 answer

How to schedule (and reset) a task programmatically with SpringFramwork?

There is a situation where I want to invoke a method after some predetermined time, say 30 sec or 5 min. Time needs to be configured at run time, means I should be able to change time dynamically from 5 min to 3 min.(reset the timer to new interval…
Sagar
  • 1,242
  • 7
  • 22
  • 49