结合Spring安全插件使用Java域对象
我正在使用遗留数据库和相应的Java域类。我正在尝试将Spring安全性添加到应用程序中,我也希望使用Java域类来实现这一点,只是为了保持一致性并将所有内容保持在一起。顺便说一句,Grails使用POGOs和POJO都没有问题 因此,从一个新的空数据库和一个新的空grails应用程序开始,我添加了Spring安全插件(acegi 0.5.1)。然后我做了:结合Spring安全插件使用Java域对象,java,grails,spring-security,Java,Grails,Spring Security,我正在使用遗留数据库和相应的Java域类。我正在尝试将Spring安全性添加到应用程序中,我也希望使用Java域类来实现这一点,只是为了保持一致性并将所有内容保持在一起。顺便说一句,Grails使用POGOs和POJO都没有问题 因此,从一个新的空数据库和一个新的空grails应用程序开始,我添加了Spring安全插件(acegi 0.5.1)。然后我做了: grails create-auth-domains org.maflt.ibidem.pojo.Person org.maflt.ibi
grails create-auth-domains org.maflt.ibidem.pojo.Person org.maflt.ibidem.pojo.Authority org.maflt.ibidem.pojo.Requestmap
这非常有效。然后我创建了POJO域类
并删除了POGO类。然后一切正常,但当应用程序启动时,我出现了以下错误:
2009-07-29 13:35:18,937 [main] ERROR context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: org.maflt.ibidem.pojo.AuthorityPeople.person in org.maflt.ibidem.pojo.Person.authorityPeoples
at java.security.AccessController.doPrivileged(Native Method)
at grails.web.container.EmbeddableServer$start.call(Unknown Source)
at _GrailsRun_groovy$_run_closure5_closure11.doCall(_GrailsRun_groovy:145)
at _GrailsRun_groovy$_run_closure5_closure11.doCall(_GrailsRun_groovy)
at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:274)
at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy)
at _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:137)
at _GrailsRun_groovy$_run_closure5.call(_GrailsRun_groovy)
at _GrailsRun_groovy.runInline(_GrailsRun_groovy:104)
at _GrailsRun_groovy.this$4$runInline(_GrailsRun_groovy)
at _GrailsRun_groovy$_run_closure1.doCall(_GrailsRun_groovy:58)
at RunApp$_run_closure1.doCall(RunApp:33)
at gant.Gant$_dispatch_closure4.doCall(Gant.groovy:324)
at gant.Gant$_dispatch_closure6.doCall(Gant.groovy:334)
at gant.Gant$_dispatch_closure6.doCall(Gant.groovy)
at gant.Gant.withBuildListeners(Gant.groovy:344)
at gant.Gant.this$2$withBuildListeners(Gant.groovy)
at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
at gant.Gant.dispatch(Gant.groovy:334)
at gant.Gant.this$2$dispatch(Gant.groovy)
at gant.Gant.invokeMethod(Gant.groovy)
at gant.Gant.processTargets(Gant.groovy:495)
at gant.Gant.processTargets(Gant.groovy:480)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: org.maflt.ibidem.pojo.AuthorityPeople.person in org.maflt.ibidem.pojo.Person.authorityPeoples
at java.security.AccessController.doPrivileged(Native Method)
... 23 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: org.maflt.ibidem.pojo.AuthorityPeople.person in org.maflt.ibidem.pojo.Person.authorityPeoples
at java.security.AccessController.doPrivileged(Native Method)
... 24 more
Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: org.maflt.ibidem.pojo.AuthorityPeople.person in org.maflt.ibidem.pojo.Person.authorityPeoples
... 25 more
2009-07-29 13:35:18,968 [main] ERROR mortbay.log - Failed startup of context org.mortbay.jetty.webapp.WebAppContext@1dfe1a{/sectest2,C:\src\netbeansprojects\sectest2/web-app}
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: org.maflt.ibidem.pojo.AuthorityPeople.person in org.maflt.ibidem.pojo.Person.authorityPeoples
at java.security.AccessController.doPrivileged(Native Method)
at grails.web.container.EmbeddableServer$start.call(Unknown Source)
at _GrailsRun_groovy$_run_closure5_closure11.doCall(_GrailsRun_groovy:145)
at _GrailsRun_groovy$_run_closure5_closure11.doCall(_GrailsRun_groovy)
at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:274)
at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy)
at _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:137)
at _GrailsRun_groovy$_run_closure5.call(_GrailsRun_groovy)
at _GrailsRun_groovy.runInline(_GrailsRun_groovy:104)
at _GrailsRun_groovy.this$4$runInline(_GrailsRun_groovy)
at _GrailsRun_groovy$_run_closure1.doCall(_GrailsRun_groovy:58)
at RunApp$_run_closure1.doCall(RunApp:33)
at gant.Gant$_dispatch_closure4.doCall(Gant.groovy:324)
at gant.Gant$_dispatch_closure6.doCall(Gant.groovy:334)
at gant.Gant$_dispatch_closure6.doCall(Gant.groovy)
at gant.Gant.withBuildListeners(Gant.groovy:344)
at gant.Gant.this$2$withBuildListeners(Gant.groovy)
at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
at gant.Gant.dispatch(Gant.groovy:334)
at gant.Gant.this$2$dispatch(Gant.groovy)
at gant.Gant.invokeMethod(Gant.groovy)
at gant.Gant.processTargets(Gant.groovy:495)
at gant.Gant.processTargets(Gant.groovy:480)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: org.maflt.ibidem.pojo.AuthorityPeople.person in org.maflt.ibidem.pojo.Person.authorityPeoples
at java.security.AccessController.doPrivileged(Native Method)
... 23 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: org.maflt.ibidem.pojo.AuthorityPeople.person in org.maflt.ibidem.pojo.Person.authorityPeoples
at java.security.AccessController.doPrivileged(Native Method)
... 24 more
Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: org.maflt.ibidem.pojo.AuthorityPeople.person in org.maflt.ibidem.pojo.Person.authorityPeoples
... 25 more
2009-07-29 13:35:19,031 [main] ERROR mortbay.log - Nested in org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: org.maflt.ibidem.pojo.AuthorityPeople.person in org.maflt.ibidem.pojo.Person.authorityPeoples:
org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: org.maflt.ibidem.pojo.AuthorityPeople.person in org.maflt.ibidem.pojo.Person.authorityPeoples
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessController.doPrivileged(Native Method)
at grails.web.container.EmbeddableServer$start.call(Unknown Source)
at _GrailsRun_groovy$_run_closure5_closure11.doCall(_GrailsRun_groovy:145)
at _GrailsRun_groovy$_run_closure5_closure11.doCall(_GrailsRun_groovy)
at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:274)
at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy)
at _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:137)
at _GrailsRun_groovy$_run_closure5.call(_GrailsRun_groovy)
at _GrailsRun_groovy.runInline(_GrailsRun_groovy:104)
at _GrailsRun_groovy.this$4$runInline(_GrailsRun_groovy)
at _GrailsRun_groovy$_run_closure1.doCall(_GrailsRun_groovy:58)
at RunApp$_run_closure1.doCall(RunApp:33)
at gant.Gant$_dispatch_closure4.doCall(Gant.groovy:324)
at gant.Gant$_dispatch_closure6.doCall(Gant.groovy:334)
at gant.Gant$_dispatch_closure6.doCall(Gant.groovy)
at gant.Gant.withBuildListeners(Gant.groovy:344)
at gant.Gant.this$2$withBuildListeners(Gant.groovy)
at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
at gant.Gant.dispatch(Gant.groovy:334)
at gant.Gant.this$2$dispatch(Gant.groovy)
at gant.Gant.invokeMethod(Gant.groovy)
at gant.Gant.processTargets(Gant.groovy:495)
at gant.Gant.processTargets(Gant.groovy:480)
java.lang.NullPointerException: Cannot invoke method list() on null object
at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:77)
at org.codehaus.groovy.runtime.InvokerHelper.invokePogoMethod(InvokerHelper.java:750)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:727)
at org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:17)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite
我的POJO如下所示:
org.maflt.ibidem.pojo.Person
package org.maflt.ibidem.pojo;
import java.util.List;
import java.io.Serializable;
import java.sql.Timestamp;
import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Transient;
import javax.persistence.Embeddable;
/**
* <p>Pojo mapping TABLE person</p>
* <p></p>
*
* <p>Generated at Wed Jul 29 11:48:39 MDT 2009</p>
* @author Salto-db Generator v1.0.16 / EJB3
*
*/
@Entity
@Table(name = "person", catalog = "test")
@SuppressWarnings("serial")
public class Person implements Serializable {
/**
* Attribute id.
*/
private Long id;
/**
* Attribute version.
*/
private Long version;
/**
* Attribute companyName.
*/
private String companyName;
/**
* Attribute description.
*/
private String description;
/**
* Attribute email.
*/
private String email;
/**
* Attribute emailShow.
*/
private Boolean emailShow;
/**
* Attribute enabled.
*/
private Boolean enabled;
/**
* Attribute passwd.
*/
private String passwd;
/**
* Attribute userRealName.
*/
private String userRealName;
/**
* Attribute username.
*/
private String username;
/**
* List of AuthorityPeople
*/
private List<AuthorityPeople> authorityPeoples = null;
/**
* <p>
* </p>
* @return id
*/
@Basic
@Id
@GeneratedValue
@Column(name = "id")
public Long getId() {
return id;
}
/**
* @param id new value for id
*/
public void setId(Long id) {
this.id = id;
}
/**
* <p>
* </p>
* @return version
*/
@Basic
@Column(name = "version")
public Long getVersion() {
return version;
}
/**
* @param version new value for version
*/
public void setVersion(Long version) {
this.version = version;
}
/**
* <p>
* </p>
* @return companyName
*/
@Basic
@Column(name = "company_name", length = 255)
public String getCompanyName() {
return companyName;
}
/**
* @param companyName new value for companyName
*/
public void setCompanyName(String companyName) {
this.companyName = companyName;
}
/**
* <p>
* </p>
* @return description
*/
@Basic
@Column(name = "description", length = 255)
public String getDescription() {
return description;
}
/**
* @param description new value for description
*/
public void setDescription(String description) {
this.description = description;
}
/**
* <p>
* </p>
* @return email
*/
@Basic
@Column(name = "email", length = 255)
public String getEmail() {
return email;
}
/**
* @param email new value for email
*/
public void setEmail(String email) {
this.email = email;
}
/**
* <p>
* </p>
* @return emailShow
*/
@Basic
@Column(name = "email_show")
public Boolean getEmailShow() {
return emailShow;
}
/**
* @param emailShow new value for emailShow
*/
public void setEmailShow(Boolean emailShow) {
this.emailShow = emailShow;
}
/**
* <p>
* </p>
* @return enabled
*/
@Basic
@Column(name = "enabled")
public Boolean getEnabled() {
return enabled;
}
/**
* @param enabled new value for enabled
*/
public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}
/**
* <p>
* </p>
* @return passwd
*/
@Basic
@Column(name = "passwd", length = 255)
public String getPasswd() {
return passwd;
}
/**
* @param passwd new value for passwd
*/
public void setPasswd(String passwd) {
this.passwd = passwd;
}
/**
* <p>
* </p>
* @return userRealName
*/
@Basic
@Column(name = "user_real_name", length = 255)
public String getUserRealName() {
return userRealName;
}
/**
* @param userRealName new value for userRealName
*/
public void setUserRealName(String userRealName) {
this.userRealName = userRealName;
}
/**
* <p>
* </p>
* @return username
*/
@Basic
@Column(name = "username", length = 255)
public String getUsername() {
return username;
}
/**
* @param username new value for username
*/
public void setUsername(String username) {
this.username = username;
}
/**
* Get the list of AuthorityPeople
*/
@OneToMany(mappedBy="person")
public List<AuthorityPeople> getAuthorityPeoples() {
return this.authorityPeoples;
}
/**
* Set the list of AuthorityPeople
*/
public void setAuthorityPeoples(List<AuthorityPeople> authorityPeoples) {
this.authorityPeoples = authorityPeoples;
}
}
原因:org.hibernate.AnnotationException:mappedBy reference一个未知的目标实体属性:org.maflt.ibidem.pojo.AuthorityPeople.person in org.maflt.ibidem.pojo.person.authorityPeoples
听起来像是一个Hibernate问题,而不是Spring安全性、POJO或grails。您可以在Person类中使用此选项:
@OneToMany(mappedBy="person")
public List<AuthorityPeople> getAuthorityPeoples() {
return this.authorityPeoples;
}
@OneToMany(mappedBy=“person”)
公共列表getAuthorityPeoples(){
返回此.authorityPeoples;
}
您的注释是指不正确的东西吗?我还没有让它工作,而且直到现在,还没有看到任何其他人也有过的证据。所以我求助于移动到grails对象。但我刚刚发现。我还没试过。我会发布我的结果,一旦我这样做
顺便说一句,如果有人想再看一看,我仍然希望得到上述实现方面的帮助。谢谢。我认为这让我朝着正确的方向前进。请查看问题的更新。更多堆栈跟踪:java.lang.NullPointerException:无法对null对象调用方法列表()。org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:121)位于org.codehaus.groovy.grails.plugins.springsecurity.RequestMapFilterInactionDefinitionHelper.loadRequestmaps(RequestMapFilterInactionDefinitionHelper.groovy:51)位于org.codehaus.groovy.grails.plugins.springsecurity.RequestmapFilterInvocationDefinition.reset(RequestmapFilterInvocationDefinition.java:57),位于org.codehaus.groovy.grails.plugins.springsecurity.RequestmapFilterI
package org.maflt.ibidem.pojo;
import java.util.List;
import java.io.Serializable;
import java.sql.Timestamp;
import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Transient;
import javax.persistence.Embeddable;
/**
* <p>Pojo mapping TABLE authority_people</p>
* <p></p>
*
* <p>Generated at Wed Jul 29 11:48:39 MDT 2009</p>
* @author Salto-db Generator v1.0.16 / EJB3
*
*/
@Entity
@Table(name = "authority_people", catalog = "test")
@SuppressWarnings("serial")
public class AuthorityPeople implements Serializable {
/**
* Primary key
*/
private AuthorityPeoplePK authorityPeoplePK;
/**
* Get the primary key
*/
@Basic
@Id
public AuthorityPeoplePK getAuthorityPeoplePK() {
return this.authorityPeoplePK;
}
/**
* set the primary key
*/
public void setAuthorityPeoplePK(AuthorityPeoplePK authorityPeoplePK) {
this.authorityPeoplePK = authorityPeoplePK;
}
/**
* <p>Composite primary key for table authority_people</p>
*
* <p>Generated at Wed Jul 29 11:48:39 MDT 2009</p>
* @author Salto-db Generator v1.0.16 / EJB3
*/
@SuppressWarnings("serial")
@Embeddable
public static class AuthorityPeoplePK implements Serializable {
/**
* Attribute authority
*/
private Authority authority;
/**
* Attribute person
*/
private Person person;
/**
* get authority
*/
@ManyToOne
@JoinColumn(name = "authority_id")
public Authority getAuthority() {
return this.authority;
}
/**
* set authority
*/
public void setAuthority(Authority authority) {
this.authority = authority;
}
/**
* get person
*/
@ManyToOne
@JoinColumn(name = "person_id")
public Person getPerson() {
return this.person;
}
/**
* set person
*/
public void setPerson(Person person) {
this.person = person;
}
/**
* calculate hashcode
*/
@Override
public int hashCode()
{
//TODO : implement this method
return super.hashCode();
}
/**
* equals method
*/
@Override
public boolean equals(Object object)
{
//TODO : implement this method
return super.equals(object);
}
}
}
package org.maflt.ibidem.pojo;
import java.util.List;
import java.io.Serializable;
import java.sql.Timestamp;
import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Transient;
import javax.persistence.Embeddable;
/**
* <p>Pojo mapping TABLE authority_people</p>
* <p></p>
*
* <p>Generated at Wed Jul 29 19:34:03 MDT 2009</p>
* @author Salto-db Generator v1.0.16 / EJB3
*
*/
@Entity
@Table(name = "authority_people", catalog = "test")
@SuppressWarnings("serial")
public class AuthorityPeople implements Serializable {
/**
* Attribute authority
*/
private Authority authority;
/**
* Attribute person
*/
private Person person;
/**
* Attribute id.
*/
private Long id;
/**
* get authority
*/
@ManyToOne
@JoinColumn(name = "authority_id")
public Authority getAuthority() {
return this.authority;
}
/**
* set authority
*/
public void setAuthority(Authority authority) {
this.authority = authority;
}
/**
* get person
*/
@ManyToOne
@JoinColumn(name = "person_id")
public Person getPerson() {
return this.person;
}
/**
* set person
*/
public void setPerson(Person person) {
this.person = person;
}
/**
* <p>
* </p>
* @return id
*/
@Basic
@Id
@Column(name = "id")
public Long getId() {
return id;
}
/**
* @param id new value for id
*/
public void setId(Long id) {
this.id = id;
}
}
java.lang.NullPointerException: Cannot invoke method list() on null object
at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:77)
at org.codehaus.groovy.runtime.InvokerHelper.invokePogoMethod(InvokerHelper.java:750)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:727)
at org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:17)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite
@OneToMany(mappedBy="person")
public List<AuthorityPeople> getAuthorityPeoples() {
return this.authorityPeoples;
}