Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring DI Unsatisfied dependency expressed
    text
    copied!<p>applicationContext.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"&gt; &lt;bean id="user" class="com.pomkine.pottyauth.domain.User"/&gt; &lt;bean id="userdao" class="com.pomkine.pottyauth.persistance.GaeUserDao"/&gt; &lt;bean id="userservice" class="com.pomkine.pottyauth.service.UserServiceImpl"&gt; &lt;constructor-arg ref="userdao"/&gt; &lt;/bean&gt; &lt;/beans&gt; </code></pre> <p>Controller:</p> <pre><code>@Controller public class RosterController { private UserService userService; @Inject public RosterController(UserService userService){ this.userService=userService; } @RequestMapping(value = {"/userRoster"}, method = RequestMethod.GET) public String showRosterPage(Map&lt;String,Object&gt; model){ model.put("users",userService.getAllUsers()); return "userRoster"; } } </code></pre> <p>So I want UserService to be injected into my controller. But I'm getting the following exception: </p> <pre><code>org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'rosterController' defined in file [S:\Coding\Idea_workspace\pottyAuth\target\pottyAuth-1.0\WEB-INF\classes\com\pomkine\pottyauth\mvc\RosterController.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [com.pomkine.pottyauth.service.UserService]: : No matching bean of type [com.pomkine.pottyauth.service.UserService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. </code></pre> <p>Here is my UserServiceImpl class:</p> <pre><code>public class UserServiceImpl implements UserService { private UserDao dao; public UserServiceImpl(UserDao dao){ this.dao=dao; } @Override public User getUser(User user) { return dao.getUser(user); } @Override public void addUser(User user) { dao.addUser(user); } @Override public List getAllUsers() { return dao.getAllUsers(); } } </code></pre> <p>So I'm expecting Spring container to create UserServiceImlp bean and inject it into RosterController. But it seems that it cannot find UserServiceImpl bean.</p> <p>What could be wrong?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload