LearnSpring | Learn and elaborate springframework source code line | Application Framework library
kandi X-RAY | LearnSpring Summary
kandi X-RAY | LearnSpring Summary
Learn and elaborate springframework source code line by line from the very beginning
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of LearnSpring
LearnSpring Key Features
LearnSpring Examples and Code Snippets
Community Discussions
Trending Discussions on LearnSpring
QUESTION
I am working on the Spring Boot project. I have a controller which uses my service class. Here is the situation, in my service class I have few class variables which I use as counters, the issue is that whenever I hit my endpoint, the values of my counter variable persists for each hit, meaning if on first request counter value is 1 then on the second hit it becomes 2 so on and on.
Shouldn't the class variables get reset for each new request? I mean the service class should be new object for each request, right?
Here is essentially what I am doing.
My controller:
...ANSWER
Answered 2021-Oct-03 at 06:14Shouldn't the class variables get reset for each new request? I mean the service class should be new object for each request, right?
No, the @Service
class is instantiated when you start your app since it's a @Bean
.
Check out how scopes and different annotations work. By default @Service
is @Scope("singleton")
so it does not get instantiated per-request and thus the variables are keeping their states.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install LearnSpring
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page