Home > Back-end >  Questions about the injected DAO service layer
Questions about the injected DAO service layer

Time:11-28

for bosses, look very desperate
Recently do SSM example there is a problem for a day, is an issue about injection failed, an error on the first
Reference
under Caused by: org. Springframework. Beans. Factory. UnsatisfiedDependencyException: Error creating bean with the name 'adminLoginService: Unsatisfied dependency expressed through the field' adminLoginDao '; Nested exception is org. Springframework. Beans. Factory. NoSuchBeanDefinitionException: No qualifying bean of type 'com. Clic. Dao. AdminLoginDao' available: expected at further 1 bean which qualifies as autowire candidate. The Dependency annotations: {@ org. Springframework. Beans. Factory. The annotation, Autowired (required=true)}


Due to the DAO layer into service service is also an error, the controller is also an error, through inspection is the DAO failed to inject into the ServiceImpl,
The following is a directory structure and applicationContext. XML configuration, the datasource and sqlSessionFactory are configured with the

 & lt; ! - open annotation scanning, hope treatment service and the dao, the controller does not need to deal with - & gt; 




followed by the code, the DAO
 @ Repository (" adminLoginDao ") 
Public interface AdminLoginDao {
/* *
* login interface
* @ param employee_num gonghaowu
* @ param "password," password
* @ return return a user
* */
@ the Select (" Select * from admininfo where employee_num=# {employee_num} and password=# {password} ")
The Admin getLoginAdmin (String employee_num, String password);

and then the service code
 @ Service (" adminLoginService ") 
Public class AdminLoginServiceImpl implements AdminLoginService {


The @autowired
Private AdminLoginDao AdminLoginDao;

@ Override
Public Admin login (String employee_num, String password) {

System. The out. Println (" the business layer query ");
The Admin Admin.=adminLoginDao getLoginAdmin (employee_num, password);
System. The out. Println (admin. GetStuff_name ());
Return the admin;
}

Service @autowired configuration, the repository of the DAO also match, mapperScanner also no problem, why is not solve

CodePudding user response:

@ Repository (" adminLoginDao ") to try @ the Repository

CodePudding user response:

"

"

You have configuration data sources,? Where is the data source configuration?
In the above & lt; Bean> Add the following try.

CodePudding user response:

I generally in the project or a tool to generate XML configuration more, see you this should be the annotation type, DAO layer is the interface to match the annotation of the @ Mapper?

CodePudding user response:

Settled, I didn't on the web. In the XML configuration ContextLoaderListener, new problems now,

 
@ the Select (" Select * from admininfo where stuff_num=# {stuff_num} and password=# {password} ")
The Admin getLoginAdmin (String stuff_num, String password);


This code execution error, follow the debug found that reflected the dao of query methods of time
Return mapperMethod. Execute (sqlSession, args) report the following error Java. Lang. Reflect. InvocationTargetException
The specific reason is
Org. Mybatis. Spring. MyBatisSystemException: nested exception is org. Apache. Ibatis. Binding. BindingException: Parameter 'stuff_num' not found. The Available parameters are [arg1, arg0 param1, param2]
The name of the database and the entity class is the same stuff_num,
Is the problem that annotations select

CodePudding user response:

reference windforce89 reply: 3/f
general projects or I use tool to generate XML configuration more, see you this should be the annotation type, DAO layer is the interface to match the annotation of the @ Mapper?
no, I'm configuration MapperScanner don't need, also follow the video to me, is less a ContextLoaderListener

CodePudding user response:

reference 4 floor Lem0nWoods response:
settled, I not in the web. In the XML configuration ContextLoaderListener, new problems now,

 
@ the Select (" Select * from admininfo where stuff_num=# {stuff_num} and password=# {password} ")
The Admin getLoginAdmin (String stuff_num, String password);


This code execution error, follow the debug found that reflected the dao of query methods of time
Return mapperMethod. Execute (sqlSession, args) report the following error Java. Lang. Reflect. InvocationTargetException
The specific reason is
Org. Mybatis. Spring. MyBatisSystemException: nested exception is org. Apache. Ibatis. Binding. BindingException: Parameter 'stuff_num' not found. The Available parameters are [arg1, arg0 param1, param2]
The name of the database and the entity class is the same stuff_num,
Is a problem of annotation the select
solved, unexpectedly is a problem of pom, replace the groupId of the c3p0 connection pool with com. McHange solved

CodePudding user response:

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related