這些問題有很多,但建議的解決方案似乎不適用於我。 我使用wicket隨着休眠和春天。我試着簡單的形式與一個文本框,但檢票口一直抱怨阿布NullPointerException
這來自自動裝配Autowired字段爲空自動佈線的字段保持爲空導致WicketRuntime異常
檢票類
public class WebLoginPage extends WebPage {
@SpringBean
IUserService userService;
private final User newUser = new User();
RequiredTextField<String> username = new RequiredTextField<String>(
"username", new PropertyModel<String>(this.newUser, "username"));
public WebLoginPage() {
final Form<?> form = new Form<User>("userForm") {
@Override
protected void onSubmit() {
WebLoginPage.this.userService
.addUser(WebLoginPage.this.newUser);
}
};
form.add(this.username);
this.add(form);
}
UserServiceImpl
package com.ziker.schedule.service;
import java.io.Serializable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import com.ziker.schedule.dao.IUserDao;
import com.ziker.schedule.pojo.User;
@Controller
public class UserServiceImpl implements IUserService, Serializable {
@Autowired
IUserDao userDao;
@Override
@Transactional
public void addUser(User user) {
this.userDao.saveUser(user);
}
@Override
@Transactional
public void deleteUser(User user) {
this.userDao.deleteUser(user);
}
}
在UserDAOImpl
package com.ziker.schedule.dao;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import com.ziker.schedule.pojo.User;
@Repository
public class UserDaoImpl implements IUserDao {
@Autowired
SessionFactory sessionFactory;
@Override
public void saveUser(User user) {
this.sessionFactory.getCurrentSession().saveOrUpdate(user);
}
@Override
public void deleteUser(User user) {
this.sessionFactory.getCurrentSession().delete(user);
}
public SessionFactory getSessionFactory() {
return this.sessionFactory;
}
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
}
的applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<context:annotation-config />
<bean id="myDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/schedule"/>
<property name="username" value="root"/>
<property name="password" value="rootroot"/>
</bean>
<bean id="mySessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="myDataSource" />
<property name="annotatedClasses">
<list>
<value>com.ziker.schedule.pojo.User</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect"> org.hibernate.dialect.HSQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
</props>
</property>
</bean>
<bean id="userDao" class="com.ziker.schedule.dao.UserDaoImpl">
<property name="sessionFactory" ref="mySessionFactory" />
</bean>
<bean id="userService" class="com.ziker.schedule.service.UserServiceImpl">
</bean>
</beans>
檢票網頁
包com.ziker.schedule.schedule;
import org.apache.wicket.Page;導入 org.apache.wicket.protocol.http.WebApplication;導入 org.apache.wicket.spring.injection.annot.SpringComponentInjector;
import com.ziker.schedule.login.WebLoginPage;
公共類ScheduleApplication延伸WebApplication的
{
@覆蓋公共類getHomePage(){返回 WebLoginPage.class; }
}
任何幫助將不勝感激香港專業教育學院也嘗試過配置,而沒有運氣註釋。對我來說,似乎我在想念着一些小事情,但一天半後,我不得不問
編輯:有問題的領域是WebLogin頁IUserService userService;
堆棧跟蹤
[qtp14429558-16] ERROR org.apache.wicket.DefaultExceptionMapper - Unexpected error occurred
org.apache.wicket.WicketRuntimeException: Method onFormSubmitted of interface org.apache.wicket.markup.html.form.IFormSubmitListener targeted at [Form [Component id = userForm]] on component [Form [Component id = userForm]] threw an exception
at org.apache.wicket.RequestListenerInterface.internalInvoke(RequestListenerInterface.java:268)
at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:216)
at org.apache.wicket.core.request.handler.ListenerInterfaceRequestHandler.invokeListener(ListenerInterfaceRequestHandler.java:241)
at org.apache.wicket.core.request.handler.ListenerInterfaceRequestHandler.respond(ListenerInterfaceRequestHandler.java:234)
at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:837)
at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64)
at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:265)
at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:222)
at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:293)
at org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(WicketFilter.java:261)
at org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:203)
at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:284)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1476)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:501)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:557)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:429)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:154)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
at org.eclipse.jetty.server.Server.handle(Server.java:370)
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:494)
at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:982)
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:1043)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:865)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:696)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:53)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.wicket.RequestListenerInterface.internalInvoke(RequestListenerInterface.java:258)
... 36 more
Caused by: java.lang.NullPointerException
at com.ziker.schedule.login.WebLoginPage$1.onSubmit(WebLoginPage.java:30)
at org.apache.wicket.markup.html.form.Form.delegateSubmit(Form.java:1262)
at org.apache.wicket.markup.html.form.Form.process(Form.java:934)
at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:766)
at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:700)
... 41 more
你沒有提及哪個autowired字段爲空,也是thr是沒有日誌 – coder 2014-08-27 16:01:53
我更新了問題,但我相信stacktrace不會有幫助,但也可能是我缺少一些東西 – Ziker 2014-08-27 16:04:30
你有沒有重寫wickets應用程序init()方法來添加SpringComponentInjector? – coder 2014-08-27 16:11:28