依赖注入失败 - 使用 full-hibernate-plugin 与 struts2 进行休眠
我正在尝试在 struts2 示例中使用 struts2 完整 hibernate 插件 (http://code.google.com/p/full-hibernate-plugin-for-struts2)。
我已将所有 Jars 放入我的 lib 文件夹中:
antlr-2.7.6.jar
commons-collections-3.1.jar
commons-fileupload-1.2.1.jar
commons-io-1.3.2.jar
commons-lang-2.3.jar
commons-logging-1.0.4.jar
commons-logging-api-1.1.jar
dom4j-1.6.1.jar
freemarker-2.3.15.jar
hibernate3.jar
javassist-3.9.0.GA.jar
jta-1.1.jar
jtds-1.2.4.jar
log4j-1.2.15.jar
ognl-2.7.3.jar
slf4j-api-1.5.8.jar
slf4j-log4j12-1.5.8.jar
spring-beans-2.5.6.jar
spring-context-2.5.6.jar
spring-core-2.5.6.jar
spring-test-2.5.6.jar
spring-web-2.5.6.jar
struts2-core-2.1.8.jar
struts2-fullhibernatecore-plugin-1.5-GA.jar
struts2-spring-plugin-2.1.8.jar
xwork-core-2.1.6.jar
这是我的操作类的代码:
package sample;
import org.hibernate.Session;
import data.*;
import java.util.*;
public class Events {
org.hibernate.Session hibernateSession;
public void setHibernateSession(org.hibernate.Session hibernateSession) throws Exception {
this.hibernateSession = hibernateSession;
}
public void sethibernateSession(org.hibernate.Session hibernateSession) throws Exception {
this.hibernateSession = hibernateSession;
}
@SuppressWarnings("unchecked")
public String execute() {
List<Event> events = hibernateSession.createQuery("from Event").list();
for (Event theEvent : events) {
// blah blah...
}
return "success";
}
}
我应该配置了完整的 hibernate 插件,将 hibernate 会话注入到我的操作类中,并在 struts.xml 中进行了此配置:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="hibernatePlugin.sessionTarget" value="hibernateSession" />
<constant name="hibernatePlugin.transactionTarget" value="hibernateTransaction" />
..etc..
</struts>
但是当我的操作类尝试访问 hibernateSession 变量时,它总是失败,它始终为空。所以依赖注入似乎失败了。
有什么想法吗? 请帮忙,非常感谢。 还要询问您是否需要查看任何其他配置文件。
i'm trying to use hibernate in a struts2 example using the struts2 full hibernate plugin (http://code.google.com/p/full-hibernate-plugin-for-struts2).
I've placed all the Jars in my lib folder:
antlr-2.7.6.jar
commons-collections-3.1.jar
commons-fileupload-1.2.1.jar
commons-io-1.3.2.jar
commons-lang-2.3.jar
commons-logging-1.0.4.jar
commons-logging-api-1.1.jar
dom4j-1.6.1.jar
freemarker-2.3.15.jar
hibernate3.jar
javassist-3.9.0.GA.jar
jta-1.1.jar
jtds-1.2.4.jar
log4j-1.2.15.jar
ognl-2.7.3.jar
slf4j-api-1.5.8.jar
slf4j-log4j12-1.5.8.jar
spring-beans-2.5.6.jar
spring-context-2.5.6.jar
spring-core-2.5.6.jar
spring-test-2.5.6.jar
spring-web-2.5.6.jar
struts2-core-2.1.8.jar
struts2-fullhibernatecore-plugin-1.5-GA.jar
struts2-spring-plugin-2.1.8.jar
xwork-core-2.1.6.jar
And here is the code to my action class:
package sample;
import org.hibernate.Session;
import data.*;
import java.util.*;
public class Events {
org.hibernate.Session hibernateSession;
public void setHibernateSession(org.hibernate.Session hibernateSession) throws Exception {
this.hibernateSession = hibernateSession;
}
public void sethibernateSession(org.hibernate.Session hibernateSession) throws Exception {
this.hibernateSession = hibernateSession;
}
@SuppressWarnings("unchecked")
public String execute() {
List<Event> events = hibernateSession.createQuery("from Event").list();
for (Event theEvent : events) {
// blah blah...
}
return "success";
}
}
I've supposedly configured the full hibernate plugin to inject the hibernate session into my action class, with this configuration in the struts.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="hibernatePlugin.sessionTarget" value="hibernateSession" />
<constant name="hibernatePlugin.transactionTarget" value="hibernateTransaction" />
..etc..
</struts>
But my action class always falls over when it tries to access the hibernateSession variable, it is always null. So the dependency injection is failing it seems.
Any ideas why?
Please help, thanks a lot.
Also ask if you need to see any other config files.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,这是问题/解决方案的集合:
Okay this was a conglomeration of problems/solutions: