Home > Back-end >  Unable to create the service beans SSM integration
Unable to create the service beans SSM integration

Time:11-21

The project structure


An error
 
Org. Springframework. Beans. Factory. NoSuchBeanDefinitionException:
No qualifying bean of type 'com. Service. UserService' available: expected at further 1 bean which qualifies as autowire candidate.
Dependency annotations: {@ javax.mail. The annotation. The Resource (shareable=true, lookup=, name=, the description=, authenticationType=CONTAINER, type=class. Java lang. Object, mappedName=)}

The applicationcontext.xml
 






UserController
 
Package com. The controller;

The import com. Service. UserService;
The import org. Springframework. Stereotype. The Controller;
The import org. Springframework. UI. Model;
The import org. Springframework. Web. Bind. The annotation. RequestMapping;
The import org. Springframework. Web. Bind. The annotation. RequestMethod;

The import javax.mail. The annotation. The Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
The import javax.mail. Servlet. HTTP. HttpSession;
import java.io.IOException;

@ Controller
Public class UserController {

@ the Resource
Private UserService UserService;

@ RequestMapping (value="https://bbs.csdn.net/topics/Login", produces="text/HTML. Charset=utf-8 ", method=RequestMethod. POST)
Public String Login (Model Model, String name, String PWD) {
Int ans=userService. UserLogin (name, PWD).
//int ans=0;
String TMP=null;
The switch (ans) {
Case 0:
TMP="please enter the user name and password".
break;
Case 1:
TMP="user name does not exist";
break;
Case 2:
TMP="password error";
break;
Case 3:
TMP="login successful + name";
Model. The addAttribute (" name ", name);
break;
}
Model. The addAttribute (" TMP ", TMP);
If (ans & lt; 3)
Return "wrong";
The else
Return "welcome";
}

@ RequestMapping (value="https://bbs.csdn.net/topics/page/Register", produces="text/HTML. Charset=utf-8 ", method=RequestMethod. POST)
Public String Register (it request, HttpServletResponse response, String name, String PWD) throws IOException {
A Boolean flag=userService. UserRegister (name, PWD).
//a Boolean flag=true;
String TMP=flag?" Registered success ":" failure ";
The HttpSession session=request. GetSession ();
The session. The setAttribute (" TMP ", TMP);
If (flag)
The return of "redirect:../index. The JSP ";
The else
Return "wrong";
}
}

UserService
 
Package com. Service;

The import com. Dao. UserMapper;
The import org. Springframework. Stereotype. Service;
The import org. Springframework. Transaction. The annotation. Transactional;
The import com. Po. The User;

The import javax.mail. The annotation. The Resource;
import java.util.HashMap;
Import the Java. Util. The Map;

@ Service
Public class UserService {
@ the Resource
Public UserMapper UserMapper.

@ Transactional
Public Boolean userRegister (String name, String PWD)
{
Map The map=new HashMap<> (a);
The map. The put (" name ", name);
The map. The put (" PWD ", PWD);
Int ans=userMapper. AddUser (map);
//int ans=1;
Return ans> 0;
}

@ Transactional
Public int userLogin (String name, String PWD) {
If (name==null | | PWD==null)
return 0;
User User=userMapper. GetUserByName (name);
//User User=null;
If (user==null)
return 1;
Else if (user. GetPwd (.) the equals (PWD))
Return 3;
The else
return 2;
}
}

Pom file
 
<? The XML version="1.0" encoding="utf-8"?>
4.0.0 & lt;/modelVersion>

Org. Example
  • Related