It turns out an error when compiling swears at the fact that it cannot create a ContactDaoImpl bin because the UserRole class UserRole not correctly use @OneToMany , and these are two different unconnected classes.

Actually these classes

UserRole

 class UserRole { @Entity @Table(name = "user_roles", uniqueConstraints = @UniqueConstraint( columnNames = { "role", "username" })) public class UserRole{ private Integer userRoleId; private User user; private String role; public UserRole() { } public UserRole(User user, String role) { this.user = user; this.role = role; } @Id @GeneratedValue(strategy = IDENTITY) @Column(name = "user_role_id", unique = true, nullable = false) public Integer getUserRoleId() { return this.userRoleId; } public void setUserRoleId(Integer userRoleId) { this.userRoleId = userRoleId; } @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "username", nullable = false) public User getUser() { return this.user; } public void setUser(User user) { this.user = user; } @Column(name = "role", nullable = false, length = 45) public String getRole() { return this.role; } public void setRole(String role) { this.role = role; } } 

ContactDaoImpl

 class ContactDaoImpl { @Repository public class ContactDAOImpl implements ContactDAO { @Autowired private SessionFactory sessionFactory; public void addContact(Contact contact) { sessionFactory.getCurrentSession().save(contact); } @SuppressWarnings("unchecked") public List<Contact> listContact() { return sessionFactory.getCurrentSession().createQuery("from Contact").list(); } public void removeContact(Integer id) { Contact contact = (Contact) sessionFactory.getCurrentSession().load( Contact.class, id); if (null != contact) { sessionFactory.getCurrentSession().delete(contact); } } } 

Stextrays:

org.springframework.beans.factory.BeanCreationException : Error create bean with name 'contactDAOImpl' : Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException : Could not autowire field: public org.hibernate.SessionFactory kz.tanikin.springtest.dao.ContactDAOImpl.sessionFactory ; nested exception is org.springframework.beans.factory.BeanCreationException : Error created bean with 'sessionFactory' name defined in ServletContext resource [ /WEB-INF/spring/data.xml ]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException : Use of @OneToMany or @ManyToMany targeting an unmapped class: springtest.domain.User.userRole[springtest.domain.UserRole]

What can be wrong? I can provide additional information

data.xml

 <bean id="userDao" class="kz.tanikin.springtest.dao.UserDaoImpl"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <bean id="myUserDetailsService" class="kz.tanikin.springtest.service.MyUserDetailsService"> <property name="userDao" ref="userDao" /> </bean> 

and there is an error

org.springframework.beans.factory.BeanCreationException: If it’s an error, it can be with its name. org.springframework.security.filterChains: it’s not necessary to identify it. with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.DefaultSecurityFilterChain # 0': Cannot create inner bean ' .security.web.authentication.logout.LogoutFilter] while setting constructor argument with key [3]; nested exception is org.springframework.beans.factory.BeanCreationException: # 7bd95c47 'Error creating bean with name' (inner bean): Can not be referenced by org.springframework. setting constructor argument with key [1]; nested exception is org.springframework.beans.factory.BeanCreationException: This is an error. constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: # 232efad5 'Error creating bean with name (inner bean): Bean instantiation via factory method failed; nested exception is org.springframework.beans. BeanInstantiationException: Failed to instantiate [org.springframework.security. nested exception is org.springframework.context.ApplicationContextException: More than one UserDetailsService registered. Please use specific reference in or elements.

    1 answer 1

    Spring complains that it cannot create the contactDAOImpl . He cannot inject a sessionFactory into it. And this he does not work, because he can not create a sessionFactory . And this, in turn, is due to the incorrect use of the @ManyToOne annotation in the UserRole class. Most likely, you did not list the User class in the Hibernate config. Or, alternatively, you marked the User class as an annotation of org.hibernate.annotations.Entity instead of javax.persistence.Entity .

    • one
      @JTan, see the last line More than one UserDetailsService registered. Please use specific reference in or elements. For some reason, Spring picked up several instances of managers of user accounts and does not know which one to use. - Nofate
    • All right, thank you - J Mas