我的 server.xml 是 这样写的 : <GlobalNamingResources>
<Environment
name="simpleValue"
type="java.lang.Integer"
value="30"/>
<Resource
auth="Container"
description="User database that can be updated and saved"
name="UserDatabase"
type="org.apache.catalina.UserDatabase"
pathname="conf/tomcat-users.xml"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"/>
<Resource
name="jdbc/REPORTDS"
type="javax.sql.DataSource"
password="dasc"
driverClassName="oracle.jdbc.driver.OracleDriver"
maxIdle="2"
maxWait="5000"
validationQuery="select * from dual"
username="dasc_753_ps"
url="jdbc:oracle:thin:@10.1.3.105:1521:ora9i"
maxActive="4"/>
</GlobalNamingResources>
web.xml
<resource-ref>
<description>DB Connection</description>
<res-ref-name>REPORTDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<Environment
name="simpleValue"
type="java.lang.Integer"
value="30"/>
<Resource
auth="Container"
description="User database that can be updated and saved"
name="UserDatabase"
type="org.apache.catalina.UserDatabase"
pathname="conf/tomcat-users.xml"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"/>
<Resource
name="jdbc/REPORTDS"
type="javax.sql.DataSource"
password="dasc"
driverClassName="oracle.jdbc.driver.OracleDriver"
maxIdle="2"
maxWait="5000"
validationQuery="select * from dual"
username="dasc_753_ps"
url="jdbc:oracle:thin:@10.1.3.105:1521:ora9i"
maxActive="4"/>
</GlobalNamingResources>
web.xml
<resource-ref>
<description>DB Connection</description>
<res-ref-name>REPORTDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
解决方案 »
- 本来好好的,一段时间没用后,Myeclipse中无法起来tomcat
- 求救求救求救求救
- 关于做音乐网站要用到什么技术啊
- 请教:如何设定控件中的事件队列
- Hibernate 回滚的问题
- 求一个java的BBS社区开源软件
- 这空指针异常太郁闷了。。。。。求大神解救我。。。。
- javascript的问题.请各位帮忙.
- struts你们用的顺利吗?struts框架不好有一点,调试不方便,Jsp页面如果出错,框架没一点反应或提示,如果这样用下去,这么容易出错,调
- 一个JB+WEBLGOIC+MSSQL配置的错误!!急!!
- 请教HttpServletRequest和HttpSession的区别?
- 菜鸟高分急问,EJB3.0实体Bean里能不能访问数据库
sessionFactory = (SessionFactory) ctx.lookup("java:comp/env/hibernate/SessionFactory");
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;public class HibernateInit
implements ServletContextListener {
public void contextDestroyed(ServletContextEvent servletContextEvent) {
}
private static SessionFactory sf;
public static SessionFactory getSessionFactory() {
return sf;
}
public void contextInitialized(ServletContextEvent servletContextEvent) {
try {
Configuration conf = new Configuration().configure();
sf = conf.buildSessionFactory();
System.out.println("SessionFactory = " + sf);
}
catch (Exception e) {
e.printStackTrace();
}
}
}这块的 sf = conf.buildSessionFactory(); 是没问题的,就差 绑定 session工厂啦 ,快 帮帮忙撒 ~oo~
xception is java.lang.InstantiationException: org.hibernate.SessionFactory]
at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceF
actory.java:102)
at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:3
04)
at org.apache.naming.NamingContext.lookup(NamingContext.java:793)
at org.apache.naming.NamingContext.lookup(NamingContext.java:140)
at org.apache.naming.NamingContext.lookup(NamingContext.java:781)
at org.apache.naming.NamingContext.lookup(NamingContext.java:140)
at org.apache.naming.NamingContext.lookup(NamingContext.java:781)
at org.apache.naming.NamingContext.lookup(NamingContext.java:140)
at org.apache.naming.NamingContext.lookup(NamingContext.java:781)
at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:137)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at com.aspire.reportSystem.common.dao.HibernateSessionFactory.currentSes
sion(HibernateSessionFactory.java:59)
at com.aspire.reportSystem.common.dao.DBdao.queryTable(DBdao.java:30)
at com.aspire.reportSystem.portal.report.htmlReport.ReportPageComponent.
getParaDetailVO(ReportPageComponent.java:405)
at com.aspire.reportSystem.portal.report.htmlReport.ReportPageComponent.
getQueryPara_ByType(ReportPageComponent.java:250)
应该改成
java:comp/env/jdbc/REPORTDS
关于配置工厂到JNDI:
在 <GlobalNamingResources>
………………
</GlobalNamingResources>
中添加一个
<Resource
auth="Container"
name="hibernate/SessionFactory"
type="com.aspire.reportSystem.common.dao.HibernateSessionFactory"
factory="这里添创建这个类工厂类的工厂类,这个类必须实现了javax.naming.spi.ObjectFactory接口"/>
然后在Web.xml中添加:
<resource-ref>
<description>sessionFactory</description>
<res-ref-name>hibernate/SessionFactory</res-ref-name>
<res-type>com.aspire.reportSystem.common.dao.HibernateSessionFactory</res-type>
<res-auth>Container</res-auth>
</resource-ref>
你工厂类和创建工厂类的类JAR包应该放到Tomcat的lib目录下。
大致就是这么一个流程,祝你好运,有什么问题再说。