In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces you to use @ Autowired annotation to introduce the server service layer method Times error solution, the content is very detailed, interested friends can refer to, hope to be helpful to you.
@ Autowired annotations introduce server service layer method Times error
ContentTypeService in com.example.demo001.controller.ContentTypeController required a bean of type 'com.example.demo001.service.ContentTypeService' that could not be found
The method of searching on the Internet: it's okay.
Method 1: @ Autowried (required = false) sets the required attribute value to false, and the error disappears
Method 2: replace @ Resource annotation with @ Autowried annotation, the error disappears
JavaBean is a special Java class, written in the Java language, and conforms to the JavaBean API specification. The unique features of JavaBean compared to other Java classes are:
1. Provide a default no-parameter constructor.
2. Need to serialize and implement the Serializable interface
3. There may be a series of readability attributes
4. There may be a series of getter or setter methods.
JavaBean attribute
The property of a JavaBean object should be accessible, which can be any legal Java data type, including a custom Java class.
The properties of a JavaBean object can be read-write, read-only, or write-only. The properties of the JavaBean object are accessed through two methods provided in the JavaBean implementation class
Method
GetPropertyName (): for example, if the name of the property is myName, then the name of the method is written as getMyName () to read the property. This method is also called an accessor.
SetPropertyName (): for example, if the name of the property is myName, then the name of the method is written as setMyName () to write the property. This method is also known as a writer.
A read-only property provides only the getPropertyName () method, and a write-only property provides only the setPropertyName () method.
What is the purpose of @ Autowried?
@ Autowried is an annotation that annotates class member variables, methods, and constructors, allowing spring to automate the assembly of bean.
@ Autowried matches by class by default, and assembles bean by name with @ Qualifier.
The real reason for the error is that it is not imported in serveImpl
When the problem is solved, attach the web address to solve the problem online. which of the above two methods can be used? it is not clear what is going on.
It's just a guide.
The above is the original xml file, if this is equivalent to @ Component of the annotation and @ Service is a @ Component derivative, and autowire is an attribute of bean in xml, so it is valid only if @ Component exists @ Autowire
About the error occurred in the @ Autowired annotation
1. Field injetion is not recommended
2. Consider defining a bean of type 'xxx' in your configuration problem occurs in spring boot automatic injection.
1. Solve
Original code
@ Autowired private final AccountDao accountDao
Error report: Field injetion is not recommended
Change to
/ / final unnecessary private final AccountDao accountDao; @ Autowired public AccountController (AccountDao accountDao) {this.accountDao = accountDao;}
The error disappears
Note: if it is still a warning, directly changing the @ Autowired annotation to @ Resource annotation can eliminate the warning (does not affect injection)
two。 Solve
Originally, account, that is, entity and dao, were put in the upper directory of controller.
Error report: Consider defining a bean of type 'xxx' in your configuration
Put entity and dao in the controler sibling directory or I put them in the account package where the sibling directory is located.
As shown in the following figure
Restart, error disappears ~
On the use of @ Autowired annotations to introduce server service layer methods Times error solutions to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.