spring-best-practice | 本项目用于展示个人在使用Spring开发的过程中总结的最佳实践
kandi X-RAY | spring-best-practice Summary
kandi X-RAY | spring-best-practice Summary
本项目用于展示个人在使用Spring开发的过程中总结的最佳实践
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Handle business exception
- Helper method to create the failed result model
- Gets username
- Get error log message
- Handle validation exception
- Handle an unknown exception
- Returns the message for the binding result
- Handles error response body
- Creates a new ResultBean with the given message
- Create docket
- API info
- Get account by id
- Creates a new result bean
- Request error message
- Insert account
- Launch the best practices application
- Add an account
- Retrieves an account with the given id
spring-best-practice Key Features
spring-best-practice Examples and Code Snippets
Community Discussions
Trending Discussions on spring-best-practice
QUESTION
Front-End dev here working on my first Java Spring Boot API. I've been reading many articles on the "best practices" in Spring/Spring Boot and have been attempting to refactor my code to follow those practices.
Below I have an example of a generic class I use to handle all HTTP requests for my various services. Originally I had this class annotated with the @Component annontation, but as I mentioned I am trying to learn and follow Spring "best practices." In particular I am interested in implementing what this article on best practices describes (Number 3 & 4 in the article). That says one should avoid using @component, because we don't want to be tightly coupled to the Spring framework and we want to avoid "entire class path scanning."
...ANSWER
Answered 2019-Aug-22 at 19:57Adding @Component
to your class forces anyone who uses your class to know about Spring (i.e. spring is a compile time dependency).
The easiest alternative is to create separate class annotated with @Configuration
in your app, and let it handle creating your class a Spring bean.
For example:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install spring-best-practice
You can use spring-best-practice like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the spring-best-practice component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
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