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 isorg.springframework.beans.factory.BeanCreationException: Could not autowire field:public org.hibernate.SessionFactory kz.tanikin.springtest.dao.ContactDAOImpl.sessionFactory; nested exception isorg.springframework.beans.factory.BeanCreationException: Error created bean with'sessionFactory'name defined inServletContextresource [/WEB-INF/spring/data.xml]: Invocation of init method failed; nested exception isorg.hibernate.AnnotationException: Use of@OneToManyor@ManyToManytargeting 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.