当前位置:编程学习 > JAVA >>

求救!!!Springsecurity3相关问题

自学SpringSecurity出现如下问题:
配置如下:
<http auto-config='true' access-denied-page="/error/403.jsp">
<intercept-url pattern="/admin.jsp" access="ROLE_ADMIN" />
<intercept-url pattern="/**" access="ROLE_USER" />
</http>
<authentication-manager >
<authentication-provider user-service-ref="appUserDao">
</authentication-provider>
实体类:
@Entity
public class Authorities {
private String username;
private int id;
private String authority;
public void setAuthority(String authority) {
this.authority = authority;
}
public String getAuthority() {
return authority;
}
public void setId(int id) {
this.id = id;
}
@Id
@GeneratedValue
public int getId() {
return id;
}
public void setUsername(String username) {
this.username = username;
}
public String getUsername() {
return username;
}
}
@Entity
public class Users implements UserDetails{

private static final long serialVersionUID = 1L;
private String username;
private String password;
private boolean enabled;
private int userid;
private Set<Authorities> authority;

public void setUserid(int userid) {
this.userid = userid;
}

@Id
@GeneratedValue
public int getUserid() {
return userid;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public boolean isEnabled() {
return enabled;
}
public void setPassword(String password) {
this.password = password;
}
public String getPassword() {
return password;
}
public void setUsername(String username) {
this.username = username;
}
public String getUsername() {
return username;
}

public Collection<GrantedAuthority> getAuthorities() {
List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
for(Authorities a : getAuthority()){
authorities.add(new GrantedAuthorityImpl(a.getUsername()));
}
return authorities;
}

public boolean isAccountNonExpired() {
return true;
}

public boolean isAccountNonLocked() {

return true;
}

public boolean isCredentialsNonExpired() {

return true;
}

public void setAuthority(Set<Authorities> authority) {
this.authority = authority;
}
@OneToMany(targetEntity=com.system.model.Authorities.class)
public Set<Authorities> getAuthority() {
return authority;
}
}
出现如下异常:
Caused by: org.hibernate.MappingException: Could not determine type for: java.util.Collection, at table: Users, for columns: [org.hibernate.mapping.Column(authorities)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:291)
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:275)
at org.hibernate.mapping.Property.isValid(Property.java:217)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:464)
at org.hibernate.mapping.RootClass.validate(RootClass.java:236)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1193)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1378)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:954)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:860)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:779)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
... 23 more

因为我觉得SpringSecurity提供UserDetails和UserDetailsService两个接口是给它自己系统用的,所以数据库不用设立authority,isAccountNonLocked等字段,所以我只建了两个表:
Users:字段username,password,userid,enabled
Authorities:字段:username,authority,id
请高手赐教!!!!!!!! --------------------编程问答-------------------- 参考Hibernate Annotation文档:Depending on whether you annotate fields or methods, the access type used by Hibernate will be field or property. The EJB3 spec requires that you declare annotations on the element type that will be accessed, i.e. the getter method if you use property access, the field if you use field access. Mixing annotations in both fields and methods should be avoided. Hibernate will guess the access type from the position of @Id or @EmbeddedId
终于找到了答案,困扰我一个星期!哎,Hibernate学得不好呀! --------------------编程问答-------------------- --------------------编程问答--------------------
引用 2 楼 caimaohua 的回复:
看来只要节分了咯

+ --------------------编程问答-------------------- [Quote=引用 3 楼 jackey_ctdw 的回复:]

引用 2 楼 caimaohua 的回复:
看来只要节分了咯

+
[/Quote] --------------------编程问答-------------------- 嘿嘿都是什么呀  乱七八糟 --------------------编程问答-------------------- http://blog.csdn.net/jiafugui/article/details/4595790
http://www.cnblogs.com/wltfighting/archive/2008/09/26/1299602.html
这两个可以看看,应该是你xml少写了一个属性 --------------------编程问答-------------------- 配置错了,看一下这个


http://blog.csdn.net/jiafugui/article/details/4595790


祝你好运
补充:Java ,  Java EE
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,