spring - java.lang.NullPointerException at org.hibernate.cfg.Configuration.configure(Configuration.java:2111) -
spring - java.lang.NullPointerException at org.hibernate.cfg.Configuration.configure(Configuration.java:2111) -
eclipse error report:
java.lang.nullpointerexception @ org.hibernate.cfg.configuration.configure(configuration.java:2111) @ org.hibernate.cfg.annotationconfiguration.configure(annotationconfiguration.java:189) @ de.mail.hibernateutil.<clinit>(hibernateutil.java:33) @ de.mail.gui.loginservlet.dopost(loginservlet.java:55) @ javax.servlet.http.httpservlet.service(httpservlet.java:641) @ javax.servlet.http.httpservlet.service(httpservlet.java:722) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:304) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:210) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:240) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:164) @ org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:462) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:164) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:100) @ org.apache.catalina.valves.accesslogvalve.invoke(accesslogvalve.java:562) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:118) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:395) @ org.apache.coyote.http11.http11processor.process(http11processor.java:250) @ org.apache.coyote.http11.http11protocol$http11connectionhandler.process(http11protocol.java:188) @ org.apache.tomcat.util.net.jioendpoint$socketprocessor.run(jioendpoint.java:302) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1145) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:615) @ java.lang.thread.run(thread.java:744)
browser/tomcat error report:
exception
javax.servlet.servletexception: servlet execution threw exception
root cause
java.lang.exceptionininitializererror de.mail.gui.loginservlet.dopost(loginservlet.java:55) javax.servlet.http.httpservlet.service(httpservlet.java:641) javax.servlet.http.httpservlet.service(httpservlet.java:722)
root cause
java.lang.nullpointerexception org.hibernate.cfg.configuration.configure(configuration.java:2111) org.hibernate.cfg.annotationconfiguration.configure(annotationconfiguration.java:189) de.mail.hibernateutil.<clinit>(hibernateutil.java:33) de.mail.gui.loginservlet.dopost(loginservlet.java:55) javax.servlet.http.httpservlet.service(httpservlet.java:641) javax.servlet.http.httpservlet.service(httpservlet.java:722)
i using spring hibernate, context.xml looks this:
<bean id="c3p0datasource" class="com.mchange.v2.c3p0.combopooleddatasource" destroy-method="close"> <property name="driverclass" value="org.postgresql.driver" /> <property name="jdbcurl" value="something" /> <property name="maxpoolsize" value="1" /> <property name="properties"> <props> <prop key="user">postgres</prop> <prop key="password">something</prop> <prop key="characterencoding">utf-8</prop> </props> </property> </bean> <alias name="c3p0datasource" alias="datasource" /> <tx:annotation-driven transaction-manager="transactionmanager"/> <bean id="transactionmanager" class="org.springframework.orm.hibernate4.hibernatetransactionmanager"> <property name="sessionfactory" ref="sessionfactory" /> <property name="nestedtransactionallowed" value="false" /> </bean> <bean id="sessionfactory" class="org.springframework.orm.hibernate4.localsessionfactorybean" destroy-method="destroy"> <property name="datasource" ref="datasource" /> <property name="hibernateproperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.postgresqldialect</prop> <prop key="hibernate.current_session_context_class">thread</prop> <prop key="hibernate.cache.provider_class">org.hibernate.cache.nocacheprovider</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> </props> </property> <property name="annotatedpackages"> <list> <value>de.mail.data.vo</value> </list> </property> </bean>
the loginservlet file looks this:
public class loginservlet extends httpservlet { private static final long serialversionuid = -776218596462464850l; private static final log log = logfactory.getlog(loginservlet.class); private static final int hex_ff = 0xff; /** * @see httpservlet#dopost(httpservletrequest request, httpservletresponse response) * @param response der httpresponse * @param request der httprequest * @throws servletexception ex * @throws ioexception ex */ @override @transactional protected void dopost(final httpservletrequest request, final httpservletresponse response) throws servletexception, ioexception { if (!"registrieren".equals(request.getparameter("register"))) { final sessionfactory mill = hibernateutil.getsessionfactory(); final session session = factory.getcurrentsession(); // generiert einen hashwert aus dem eingegebenen passwort seek { final byte[] pwbytes = request.getparameter("password").getbytes(); final messagedigest algorithm = messagedigest.getinstance("md5"); algorithm.reset(); algorithm.update(pwbytes); final byte[] messagedigest = algorithm.digest(); final stringbuffer hexstring = new stringbuffer(); (byte digest : messagedigest) { hexstring.append(integer.tohexstring(hex_ff & digest)); } final logindao dao = new logindao(); final list<uservo> list = dao.checklogin(request, session); final uservo uservo = list.get(0); if (uservo.getpassword().equals(hexstring.tostring())) { request.getsession().setattribute("userid", uservo.getid()); final requestdispatcher dispatcher = request.getrequestdispatcher("main.jsp"); dispatcher.forward(request, response); } else { final requestdispatcher dispatcher = request.getrequestdispatcher("login.jsp"); dispatcher.forward(request, response); } } grab (nosuchalgorithmexception nsax) { log.debug("keine messagedigestspi fuer den entsprechenden alogrithmus gefunden"); } grab (nullpointerexception npx) { final requestdispatcher dispatcher = request.getrequestdispatcher("login.jsp"); dispatcher.forward(request, response); } grab (indexoutofboundsexception ioobx) { final requestdispatcher dispatcher = request.getrequestdispatcher("login.jsp"); dispatcher.forward(request, response); } } else { final requestdispatcher dispatcher = request.getrequestdispatcher("register.jsp"); dispatcher.forward(request, response); } } /** * @see httpservlet#doget(httpservletrequest request, httpservletresponse response) * @param response der httpresponse * @param request der httprequest * @throws servletexception ex * @throws ioexception ex */ @override protected void doget(final httpservletrequest request, final httpservletresponse response) throws servletexception, ioexception { dopost(request, response); } }
hibernateutil:
@suppresswarnings("deprecation") public final class hibernateutil { private static sessionfactory sessionfactory; private static final string config_file = "hibernate.cfg.xml"; /** * standardkonstruktor */ private hibernateutil() { // avoid creation of utility-class } static { url url = hibernate.class.getclassloader().getresource(config_file); configuration cfg = new annotationconfiguration().configure(url); sessionfactory = cfg.buildsessionfactory(); } /** * * @return ret */ public static sessionfactory getsessionfactory() { homecoming sessionfactory; } /** * Öffnet eine session * * @return die geöffnete session * @throws hibernateexception * hex */ public static session getsession() throws hibernateexception { homecoming hibernateutil.sessionfactory.opensession(); } /** * hibernateutil.java schließt alle db-verbindungen und alle caches */ public void shutdown() { hibernateutil.sessionfactory.getcurrentsession().close(); hibernateutil.sessionfactory.close(); } }
i know code isn't best, i'm new spring , old project in had implement spring.
i face literally no thought causes error. i've searched whole web days now... if has suggestion or improve solution pretty happy.
when looked code after weekend solution right there...
the problem hibernateutil:
private static final string config_file = "hibernate.cfg.xml";
pretty fail guess, when trying configure hibernate via context.xml :p
java spring hibernate servlets
Comments
Post a Comment