Spring classNotFound在创建spring bean时

时间:2015-04-01 11:18:50

标签: java spring spring-mvc

当我创建名为userSevice的bean时,我得到了classNotFound Exception。我正在使用spring web-mvc和spring-security

我的bean在servlet.xml中

<bean id="userService" class="tr.com.xxx.service.UserService"></bean>

这个类我想创建它的bean

public class UserService implements UserDetailsService {

@Autowired
private AccountRepository accountRepository;

@PostConstruct  
protected void initialize() {
    //accountRepository.save(new Account("user", "demo", "ROLE_USER"));
    //accountRepository.save(new Account("admin", "admin", "ROLE_ADMIN"));
    System.out.print("inside aouth");
}

@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    System.out.print("inside loadByUserName");
    Account account = accountRepository.findByEmail(username);
    if(account == null) {
        throw new UsernameNotFoundException("user not found");
    }
    return createUser(account);
}

public void signin(Account account) {
    System.out.print("sign in");
    SecurityContextHolder.getContext().setAuthentication(authenticate(account));
}

private Authentication authenticate(Account account) {
    System.out.print("inside authenticate");
    return new UsernamePasswordAuthenticationToken(createUser(account), null, account.getAuthorities());
}

private User createUser(Account account) {
    System.out.print("inside cu");
    return new User(account);
}

private static class User extends org.springframework.security.core.userdetails.User {

    private final Account account;

    public User(Account account) {
        super(account.getEmail(), account.getPassword(), account.getAuthorities());
        this.account = account;
        System.out.print("inside user");
    }

    public Account getAccount() {
        return account;
    }

    public boolean isAdmin() {
        return getAccount().isAdmin();
    }
}

}

我的错误:

Caused by: java.lang.ClassNotFoundException: tr.com.xxx.service.UserService
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:247)
at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:395)
at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1348)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1319)
... 18 more

0 个答案:

没有答案