UserDetailService
という名前のカスタムを定義しましたがUserService
、正常に動作します。いくつかのBeanで自動配線すると、エラーが発生します
org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.restaurant.service.UserService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
このフォーラムでこれに関連するすべての回答済みの解決策を確認しましたが、問題を解決するのに役立たなかったため、質問を再度投稿します。
私のrootcontext.xml
私には「context:annotation-config
」タグが含まれており、私のwebcontext.xml
私には が含まれてい"context:component-scan base-package="com.restaurant""
ます。UserService
また、サーバーの起動時にのデフォルトのコンストラクターが呼び出されることも確認しました。ただし、他の Bean への自動配線は機能しません。custom を除く他のすべての autowire は機能しますUserDetailService
。
この問題に完全に迷子になっているので、誰かがそれを解決するのを手伝ってくれますか?
私のカスタム UserService クラスは次のようになります。
@Service
public class UserService implements UserDetailsService
{
@Autowired
private UserDAO userDAO;
public UserDetails loadUserByUsername(String username)throws UsernameNotFoundException, DataAccessException {
User user = userDAO.findUnique("select usr from User usr where usr.isActive = 1 and usr.userName = ?", username);
if(user == null) {
throw new UsernameNotFoundException("User not found");
}
return user;
}
}