1

Hi I am new at spring and hibernate and i tried to create a project. I have researched and applied some techniques but i coulnt solve a problem. When I tried to access a service component in a controller, it returns null. Will it be about my missing configuration in spring? Please help me to solve the problem... thanks in advance..

UserController file:

@Controller
public class UserController {

    private UserService userService;

    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public String loginChk(ModelMap model, WebRequest req) {

        User u = userService.getByEmailPwd(email, pwd);
       /* ........ */       

        return "login";

    }
}


@Service("userService")    
public class UserServiceImp extends GenericManagerImp<User> implements  UserService 
{

    @Autowired
    UserDao userDao;

    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

    @Autowired
    public UserServiceImp(UserDao userDao) {
        super(userDao);
        this.userDao = userDao;
    }

    public User getByEmailPwd(String email, String pwd) {

        return userDao.getByEmailPwd(email, pwd);
    }
}
3
  • 1
    Add @Autowired over the property. Commented Jun 12, 2014 at 12:10
  • IT worked thank you very very veryyy mcuh i was goingto be crazy :) Commented Jun 12, 2014 at 12:16
  • I have added this commant as Answer feel free to upvote or accept thsi. Commented Jun 12, 2014 at 12:17

1 Answer 1

1

Add @Autowired over the property

Sign up to request clarification or add additional context in comments.

15 Comments

Can you add the whole stacktrace to your question please?
Unfortunatelly i counld not beacuse of my status on stackoverflow.com I am a new user so I count send eevrthing :(
sory to send the stacktrace by this way
You have to add a default constructor to your bean. public UserServiceImp(){}
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void com.article.dao.GenericDaoImp.setSessionFactory(org.hibernate.SessionFactory); nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.hibernate.SessionFactory] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.