1

我正在尝试将休眠与 servlet 一起使用。由于 SessionFactory 需要花费大量时间来初始化,我决定在 init 方法中构建会话工厂。下面是我的 servlet 代码。

public void init()throws ServletException
{
    factory = new Configuration().configure().buildSessionFactory();

}

但我得到如下错误。

Sep 10, 2013 4:27:12 PM org.apache.catalina.core.ApplicationContext log
INFO: Marking servlet cgi as unavailable
Sep 10, 2013 4:27:12 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet /school threw load() exception
java.lang.SecurityException: Restricted class org.apache.catalina.servlets.CGIServlet
at  org.apache.catalina.core.DefaultInstanceManager.checkAccess(DefaultInstanceManager.java:432)
at org.apache.catalina.core.DefaultInstanceManager.checkAccess(DefaultInstanceManager.java:423)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:399)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:118)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1099)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1043)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4957)
at org.apache.catalina.core.StandardContext$3.call(StandardContext.java:5284)
at org.apache.catalina.core.StandardContext$3.call(StandardContext.java:5279)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)

Sep 10, 2013 4:27:52 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [StaffAttendanceReport] in context with path    [/school] threw exception [Servlet execution threw an exception] with root cause
java.lang.ClassNotFoundException: org.dom4j.DocumentException
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at com.enext.security.base.BaseServlet.getSessionFactory(BaseServlet.java:45)
at com.enext.edu.school.attendance.servlet.StaffAttendanceReport.service(StaffAttendanceReport.java:56)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.smartware.antisql.AntiSQLFilter.doFilter(AntiSQLFilter.java:102)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at Filters.BlockSplChrFliter.doFilter(BlockSplChrFliter.java:46)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:185)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:151)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:269)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)

这个例外是什么意思。

SEVERE: Servlet /school threw load() exception
java.lang.SecurityException: Restricted class org.apache.catalina.servlets.CGIServlet

我更改了tomcat并尝试了相同的异常

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.

下面是我的 hibernate.cfg.xml 文件

<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@ip:port:sid</property>
<property name="hibernate.connection.username">uname</property>
<property name="hibernate.connection.password">passwd</property>       
<mapping resource="com/enext/edu/school/attendance/entity/EmployeeMaster.hbm.xml"/>
<mapping resource="com/enext/edu/school/attendance/entity/StudentHolidayMasterBean.hbm.xml"/>    
<mapping resource="com/enext/edu/school/attendance/entity/EmployeeSignin.hbm.xml"/>
</session-factory>
</hibernate-configuration>

我该如何解决这个问题?

4

2 回答 2

0

似乎有些罐子不见了..dom4j-1.5.2.jar 你得到Caused by: java.lang.ClassNotFoundException: org.dom4j.DocumentException

于 2013-09-10T10:32:20.297 回答
0

似乎你缺少dom4j罐子,请确保你有这些依赖

<dependency>
        <groupId>dom4j</groupId>
        <artifactId>dom4j</artifactId>
        <version><version></version>
    </dependency>
于 2013-09-10T10:32:44.587 回答