- 浏览: 19744 次
- 性别:
- 来自: 北京
最近访客 更多访客>>
文章分类
最新评论
-
fly_0921:
把<bean id="login" ...
求助!!action里调用dao出现空指针错误,发现dao为null,不知为何? -
raybb:
好像是applicationContext.xml没有被加载进 ...
求助!!action里调用dao出现空指针错误,发现dao为null,不知为何? -
raybb:
jessdy 写道userDao为空,貌似没注入?Debug一 ...
求助!!action里调用dao出现空指针错误,发现dao为null,不知为何? -
jessdy:
userDao为空,貌似没注入?Debug一下?
求助!!action里调用dao出现空指针错误,发现dao为null,不知为何?
不好意思 代码比较多,不过很容易看懂,userDAO注入进来为null,new一个userDAO,提示操作失败,说dao有问题,这几写个测试类,dao却没有问题
Login.javapackage action;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import dao.user.UserDAO;
import domain.user.User;
import com.opensymphony.xwork.Action;
import com.opensymphony.xwork.ActionContext;
public class Login implements Action {
private User user = new User();
private UserDAO userDAO;
public String execute() throws Exception {
// TODO Auto-generated method stub
System.out.println("Start execute......。。。。。。。。。。。。。。");
System.out.println("User="+user.getName());
if(user.getName()==null||user.getName().equals("")||user.getPassword()==null||user.getPassword().equals("")){
return INPUT;
}else{
List l = userDAO.findByProperty("name", user.getName());//就在这行出现空指针错误,userDAO为null
Iterator i = l.iterator();
User users=null;
while(i.hasNext()){
users = (User)i.next();
System.out.println("User="+users.getName());
}
if(user.getName().equals(users.getName())){
return SUCCESS;
}
return null;
}
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public UserDAO getUserDAO() {
return userDAO;
}
public void setUserDAO(UserDAO userDAO) {
this.userDAO = userDAO;
}
}
UserDAO.java
package dao.user;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.LocalSessionFactoryBean;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import domain.user.User;;
/**
* Data access object (DAO) for domain model class user.
* @see .user
* @author MyEclipse - Hibernate Tools
*/
public class UserDAO extends HibernateDaoSupport implements IBaseHibernateDAO {
private static final Log log = LogFactory.getLog(UserDAO.class);
private LocalSessionFactoryBean sessionFactory;
public void setSessionFactory(LocalSessionFactoryBean sessionFactory) {
this.sessionFactory = sessionFactory;
}
/* (non-Javadoc)
* @see dao.a#save(domain.user.User)
*/
public void save(User transientInstance) {
log.debug("saving user instance");
try {
getHibernateTemplate().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public List findByProperty(String propertyName, Object value) {
log.debug("finding User instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from User as model where model."
+ propertyName + "= ?";
return getHibernateTemplate().find(queryString, value);
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
}
UserDAOTest.java userDAO的测试类,结果没问题
package testConnection;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import dao.user.UserDAO;
import domain.user.User;;
public class UserDAOTest {
public static void main(String[] args) {
ApplicationContext context = new FileSystemXmlApplicationContext("WebRoot/WEB-INF/applicationContext.xml");
UserDAO userDAO =(UserDAO)context.getBean("userDAO");
logger.debug("初始化成功");
System.out.print("初始化成功");
List l = userDAO.findByProperty("name", "ray");
Iterator i = l.iterator();
while(i.hasNext()){
User u = (User)i.next();
System.out.println(u.getPassword());
}
}
}
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="placeholderConfig"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>WEB-INF/init.properties</value>
</list>
</property>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName">
<value>${dataSource.driverClassName}</value>
</property>
<property name="url">
<value>${dataSource.url}</value>
</property>
<property name="username"><value>${dataSource.username}</value></property>
<property name="password"><value>${dataSource.password}</value></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
</props>
</property>
<property name="mappingResources">
<list>
<!-- 加u-28803 映u23556 文u20214 -->
<value>User.hbm.xml</value>
</list>
</property>
</bean>
<bean id="login" class="action.Login">
<property name="userDAO">
<ref bean="userDAO" />
</property>
</bean>
<bean id="userDAO" class="dao.user.UserDAO" dependency-check="all">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
</beans>
xwork.xml
<!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork 1.0//EN" "http://www.opensymphony.com/xwork/xwork-1.0.dtd">
<xwork>
<include file="webwork-default.xml"/>
<include file="config-browser.xml"/>
<package name="default" extends="webwork-default">
<action name="login" class="action.Login">
<result name="success" type="dispatcher">
<param name="location">/success.jsp</param>
</result>
<result name="input" type="dispatcher">
<param name="location">/success.jsp</param>
</result>
<interceptor-ref name="params"/>
</action>
</package>
</xwork>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>webwork</servlet-name>
<servlet-class>com.opensymphony.webwork.dispatcher.ServletDispatcher</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>webwork</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>
<taglib>
<taglib-uri>webwork</taglib-uri>
<taglib-location>/WEB-INF/taglib.tld</taglib-location>
</taglib>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
Login.javapackage action;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import dao.user.UserDAO;
import domain.user.User;
import com.opensymphony.xwork.Action;
import com.opensymphony.xwork.ActionContext;
public class Login implements Action {
private User user = new User();
private UserDAO userDAO;
public String execute() throws Exception {
// TODO Auto-generated method stub
System.out.println("Start execute......。。。。。。。。。。。。。。");
System.out.println("User="+user.getName());
if(user.getName()==null||user.getName().equals("")||user.getPassword()==null||user.getPassword().equals("")){
return INPUT;
}else{
List l = userDAO.findByProperty("name", user.getName());//就在这行出现空指针错误,userDAO为null
Iterator i = l.iterator();
User users=null;
while(i.hasNext()){
users = (User)i.next();
System.out.println("User="+users.getName());
}
if(user.getName().equals(users.getName())){
return SUCCESS;
}
return null;
}
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public UserDAO getUserDAO() {
return userDAO;
}
public void setUserDAO(UserDAO userDAO) {
this.userDAO = userDAO;
}
}
UserDAO.java
package dao.user;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.LocalSessionFactoryBean;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import domain.user.User;;
/**
* Data access object (DAO) for domain model class user.
* @see .user
* @author MyEclipse - Hibernate Tools
*/
public class UserDAO extends HibernateDaoSupport implements IBaseHibernateDAO {
private static final Log log = LogFactory.getLog(UserDAO.class);
private LocalSessionFactoryBean sessionFactory;
public void setSessionFactory(LocalSessionFactoryBean sessionFactory) {
this.sessionFactory = sessionFactory;
}
/* (non-Javadoc)
* @see dao.a#save(domain.user.User)
*/
public void save(User transientInstance) {
log.debug("saving user instance");
try {
getHibernateTemplate().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public List findByProperty(String propertyName, Object value) {
log.debug("finding User instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from User as model where model."
+ propertyName + "= ?";
return getHibernateTemplate().find(queryString, value);
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
}
UserDAOTest.java userDAO的测试类,结果没问题
package testConnection;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import dao.user.UserDAO;
import domain.user.User;;
public class UserDAOTest {
public static void main(String[] args) {
ApplicationContext context = new FileSystemXmlApplicationContext("WebRoot/WEB-INF/applicationContext.xml");
UserDAO userDAO =(UserDAO)context.getBean("userDAO");
logger.debug("初始化成功");
System.out.print("初始化成功");
List l = userDAO.findByProperty("name", "ray");
Iterator i = l.iterator();
while(i.hasNext()){
User u = (User)i.next();
System.out.println(u.getPassword());
}
}
}
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="placeholderConfig"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>WEB-INF/init.properties</value>
</list>
</property>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName">
<value>${dataSource.driverClassName}</value>
</property>
<property name="url">
<value>${dataSource.url}</value>
</property>
<property name="username"><value>${dataSource.username}</value></property>
<property name="password"><value>${dataSource.password}</value></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
</props>
</property>
<property name="mappingResources">
<list>
<!-- 加u-28803 映u23556 文u20214 -->
<value>User.hbm.xml</value>
</list>
</property>
</bean>
<bean id="login" class="action.Login">
<property name="userDAO">
<ref bean="userDAO" />
</property>
</bean>
<bean id="userDAO" class="dao.user.UserDAO" dependency-check="all">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
</beans>
xwork.xml
<!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork 1.0//EN" "http://www.opensymphony.com/xwork/xwork-1.0.dtd">
<xwork>
<include file="webwork-default.xml"/>
<include file="config-browser.xml"/>
<package name="default" extends="webwork-default">
<action name="login" class="action.Login">
<result name="success" type="dispatcher">
<param name="location">/success.jsp</param>
</result>
<result name="input" type="dispatcher">
<param name="location">/success.jsp</param>
</result>
<interceptor-ref name="params"/>
</action>
</package>
</xwork>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>webwork</servlet-name>
<servlet-class>com.opensymphony.webwork.dispatcher.ServletDispatcher</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>webwork</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>
<taglib>
<taglib-uri>webwork</taglib-uri>
<taglib-location>/WEB-INF/taglib.tld</taglib-location>
</taglib>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
评论
4 楼
fly_0921
2007-06-15
把<bean id="login" class="action.Login"> 这里改成
<bean id="login" class="action.Login" singleton="false>
注意一定是singleton="false",因为xwork的action是这样要求的.
还有你那个 <action name="login" class="action.Login"> 和application.xml不一致.
建议:<action name="login" class="action.Login"> 的 class="action.Login"> 就与<bean id="login" class="action.Login"> 的 <bean name="some-action">一致
<bean id="login" class="action.Login" singleton="false>
注意一定是singleton="false",因为xwork的action是这样要求的.
还有你那个 <action name="login" class="action.Login"> 和application.xml不一致.
建议:<action name="login" class="action.Login"> 的 class="action.Login"> 就与<bean id="login" class="action.Login"> 的 <bean name="some-action">一致
3 楼
raybb
2007-05-28
好像是applicationContext.xml没有被加载进去,在action里
/*ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
UserDAO userDAO =(UserDAO)context.getBean("userDAO"); */
显示加载下就可以了,但我在web.xml里已经用个监听器加载了,
2007-5-28 13:46:36 org.apache.coyote.http11.Http11AprProtocol init
信息: Initializing Coyote HTTP/1.1 on http-8080
2007-5-28 13:46:36 org.apache.coyote.ajp.AjpAprProtocol init
信息: Initializing Coyote AJP/1.3 on ajp-8009
2007-5-28 13:46:36 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 1219 ms
2007-5-28 13:46:36 org.apache.catalina.core.StandardService start
信息: Starting service Catalina
2007-5-28 13:46:36 org.apache.catalina.core.StandardEngine start
信息: Starting Servlet Engine: Apache Tomcat/5.5.17
2007-5-28 13:46:36 org.apache.catalina.core.StandardHost start
信息: XML validation disabled
2007-5-28 13:46:38 org.apache.catalina.core.ApplicationContext log
信息: org.apache.webapp.balancer.BalancerFilter: init(): ruleChain: [org.apache.webapp.balancer.RuleChain: [org.apache.webapp.balancer.rules.URLStringMatchRule: Target string: News / Redirect URL: http://www.cnn.com], [org.apache.webapp.balancer.rules.RequestParameterRule: Target param name: paramName / Target param value: paramValue / Redirect URL: http://www.yahoo.com], [org.apache.webapp.balancer.rules.AcceptEverythingRule: Redirect URL: http://jakarta.apache.org]]
2007-5-28 13:46:38 org.apache.catalina.core.ApplicationContext log
信息: ContextListener: contextInitialized()
2007-5-28 13:46:38 org.apache.catalina.core.ApplicationContext log
信息: SessionListener: contextInitialized()
2007-5-28 13:46:38 org.apache.catalina.loader.WebappClassLoader validateJarFile
信息: validateJarFile(C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\note\WEB-INF\lib\j2ee.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
2007-5-28 13:46:38 org.apache.catalina.loader.WebappClassLoader validateJarFile
信息: validateJarFile(C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\note\WEB-INF\lib\servlet-api.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
[INFO] 2007-05-28 13:46:39,515 org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization started
[INFO] 2007-05-28 13:46:39,531 org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/note] - Loading Spring root WebApplicationContext
[INFO] 2007-05-28 13:46:39,828 org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]
[INFO] 2007-05-28 13:46:41,125 org.springframework.web.context.support.XmlWebApplicationContext - Bean factory for application context [Root WebApplicationContext]: org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [dataSource,sessionFactory,userDAO,login]; root of BeanFactory hierarchy
[INFO] 2007-05-28 13:46:41,187 org.springframework.web.context.support.XmlWebApplicationContext - 4 beans defined in application context [Root WebApplicationContext]
[INFO] 2007-05-28 13:46:41,218 org.springframework.core.CollectionFactory - JDK 1.4+ collections available
[INFO] 2007-05-28 13:46:41,250 org.springframework.web.context.support.XmlWebApplicationContext - Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@15ad1da]
[INFO] 2007-05-28 13:46:41,265 org.springframework.web.context.support.XmlWebApplicationContext - Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster@1ca1a68]
[INFO] 2007-05-28 13:46:41,296 org.springframework.ui.context.support.UiApplicationContextUtils - Unable to locate ThemeSource with name 'themeSource': using default [org.springframework.ui.context.support.ResourceBundleThemeSource@15d4273]
[INFO] 2007-05-28 13:46:41,312 org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in factory [org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [dataSource,sessionFactory,userDAO,login]; root of BeanFactory hierarchy]
[INFO] 2007-05-28 13:46:41,593 org.hibernate.cfg.Environment - Hibernate 3.0.5
[INFO] 2007-05-28 13:46:41,625 org.hibernate.cfg.Environment - hibernate.properties not found
[INFO] 2007-05-28 13:46:41,625 org.hibernate.cfg.Environment - using CGLIB reflection optimizer
[INFO] 2007-05-28 13:46:41,640 org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
[INFO] 2007-05-28 13:46:42,625 org.hibernate.cfg.HbmBinder - Mapping class: domain.user.User -> user
[INFO] 2007-05-28 13:46:42,718 org.springframework.orm.hibernate3.LocalSessionFactoryBean - Building new Hibernate SessionFactory
[INFO] 2007-05-28 13:46:42,718 org.hibernate.cfg.Configuration - processing extends queue
[INFO] 2007-05-28 13:46:42,718 org.hibernate.cfg.Configuration - processing collection mappings
[INFO] 2007-05-28 13:46:42,718 org.hibernate.cfg.Configuration - processing association property references
[INFO] 2007-05-28 13:46:42,734 org.hibernate.cfg.Configuration - processing foreign key constraints
[INFO] 2007-05-28 13:46:42,968 org.hibernate.connection.ConnectionProviderFactory - Initializing connection provider: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider
[INFO] 2007-05-28 13:46:43,546 org.hibernate.cfg.SettingsFactory - RDBMS: MySQL, version: 5.0.22-community-nt
[INFO] 2007-05-28 13:46:43,546 org.hibernate.cfg.SettingsFactory - JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.1.10 ( $Date: 2005/05/19 15:52:23 $, $Revision: 1.1.2.2 $ )
[INFO] 2007-05-28 13:46:43,640 org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.MySQLDialect
[INFO] 2007-05-28 13:46:43,671 org.hibernate.transaction.TransactionFactoryFactory - Using default transaction strategy (direct JDBC transactions)
[INFO] 2007-05-28 13:46:43,687 org.hibernate.transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
[INFO] 2007-05-28 13:46:43,703 org.hibernate.cfg.SettingsFactory - Automatic flush during beforeCompletion(): disabled
[INFO] 2007-05-28 13:46:43,703 org.hibernate.cfg.SettingsFactory - Automatic session close at end of transaction: disabled
[INFO] 2007-05-28 13:46:43,703 org.hibernate.cfg.SettingsFactory - JDBC batch size: 15
[INFO] 2007-05-28 13:46:43,703 org.hibernate.cfg.SettingsFactory - JDBC batch updates for versioned data: disabled
[INFO] 2007-05-28 13:46:43,718 org.hibernate.cfg.SettingsFactory - Scrollable result sets: enabled
[INFO] 2007-05-28 13:46:43,718 org.hibernate.cfg.SettingsFactory - JDBC3 getGeneratedKeys(): enabled
[INFO] 2007-05-28 13:46:43,718 org.hibernate.cfg.SettingsFactory - Connection release mode: on_close
[INFO] 2007-05-28 13:46:43,718 org.hibernate.cfg.SettingsFactory - Maximum outer join fetch depth: 2
[INFO] 2007-05-28 13:46:43,718 org.hibernate.cfg.SettingsFactory - Default batch fetch size: 1
[INFO] 2007-05-28 13:46:43,734 org.hibernate.cfg.SettingsFactory - Generate SQL with comments: disabled
[INFO] 2007-05-28 13:46:43,734 org.hibernate.cfg.SettingsFactory - Order SQL updates by primary key: disabled
[INFO] 2007-05-28 13:46:43,734 org.hibernate.cfg.SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
[INFO] 2007-05-28 13:46:43,750 org.hibernate.hql.ast.ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory
[INFO] 2007-05-28 13:46:43,750 org.hibernate.cfg.SettingsFactory - Query language substitutions: {}
[INFO] 2007-05-28 13:46:43,750 org.hibernate.cfg.SettingsFactory - Second-level cache: enabled
[INFO] 2007-05-28 13:46:43,750 org.hibernate.cfg.SettingsFactory - Query cache: disabled
[INFO] 2007-05-28 13:46:43,750 org.hibernate.cfg.SettingsFactory - Cache provider: org.hibernate.cache.EhCacheProvider
[INFO] 2007-05-28 13:46:43,781 org.hibernate.cfg.SettingsFactory - Optimize cache for minimal puts: disabled
[INFO] 2007-05-28 13:46:43,781 org.hibernate.cfg.SettingsFactory - Structured second-level cache entries: disabled
[INFO] 2007-05-28 13:46:43,812 org.hibernate.cfg.SettingsFactory - Echoing all SQL to stdout
[INFO] 2007-05-28 13:46:43,812 org.hibernate.cfg.SettingsFactory - Statistics: disabled
[INFO] 2007-05-28 13:46:43,812 org.hibernate.cfg.SettingsFactory - Deleted entity synthetic identifier rollback: disabled
[INFO] 2007-05-28 13:46:43,812 org.hibernate.cfg.SettingsFactory - Default entity-mode: pojo
[INFO] 2007-05-28 13:46:44,218 org.hibernate.impl.SessionFactoryImpl - building session factory
[WARN] 2007-05-28 13:46:44,250 net.sf.ehcache.config.Configurator - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/C:/Program%20Files/Apache%20Software%20Foundation/Tomcat%205.5/webapps/note/WEB-INF/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
[INFO] 2007-05-28 13:46:45,484 org.hibernate.impl.SessionFactoryObjectFactory - Not binding factory to JNDI, no JNDI name configured
[INFO] 2007-05-28 13:46:45,484 org.hibernate.impl.SessionFactoryImpl - Checking 0 named queries
[INFO] 2007-05-28 13:46:45,609 org.springframework.web.context.ContextLoader - Using context class [org.springframework.web.context.support.XmlWebApplicationContext] for root WebApplicationContext
[INFO] 2007-05-28 13:46:45,625 org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization completed in 6110 ms
2007-5-28 13:46:45 org.apache.catalina.core.ApplicationContext log
信息: ContextListener: contextInitialized()
2007-5-28 13:46:45 org.apache.catalina.core.ApplicationContext log
信息: SessionListener: contextInitialized()
2007-5-28 13:46:46 org.apache.coyote.http11.Http11AprProtocol start
信息: Starting Coyote HTTP/1.1 on http-8080
2007-5-28 13:46:46 org.apache.coyote.ajp.AjpAprProtocol start
信息: Starting Coyote AJP/1.3 on ajp-8009
2007-5-28 13:46:46 org.apache.catalina.storeconfig.StoreLoader load
信息: Find registry server-registry.xml at classpath resource
2007-5-28 13:46:46 org.apache.catalina.startup.Catalina start
信息: Server startup in 10172 ms
这是信息,不知道为什么还是不行
/*ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
UserDAO userDAO =(UserDAO)context.getBean("userDAO"); */
显示加载下就可以了,但我在web.xml里已经用个监听器加载了,
2007-5-28 13:46:36 org.apache.coyote.http11.Http11AprProtocol init
信息: Initializing Coyote HTTP/1.1 on http-8080
2007-5-28 13:46:36 org.apache.coyote.ajp.AjpAprProtocol init
信息: Initializing Coyote AJP/1.3 on ajp-8009
2007-5-28 13:46:36 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 1219 ms
2007-5-28 13:46:36 org.apache.catalina.core.StandardService start
信息: Starting service Catalina
2007-5-28 13:46:36 org.apache.catalina.core.StandardEngine start
信息: Starting Servlet Engine: Apache Tomcat/5.5.17
2007-5-28 13:46:36 org.apache.catalina.core.StandardHost start
信息: XML validation disabled
2007-5-28 13:46:38 org.apache.catalina.core.ApplicationContext log
信息: org.apache.webapp.balancer.BalancerFilter: init(): ruleChain: [org.apache.webapp.balancer.RuleChain: [org.apache.webapp.balancer.rules.URLStringMatchRule: Target string: News / Redirect URL: http://www.cnn.com], [org.apache.webapp.balancer.rules.RequestParameterRule: Target param name: paramName / Target param value: paramValue / Redirect URL: http://www.yahoo.com], [org.apache.webapp.balancer.rules.AcceptEverythingRule: Redirect URL: http://jakarta.apache.org]]
2007-5-28 13:46:38 org.apache.catalina.core.ApplicationContext log
信息: ContextListener: contextInitialized()
2007-5-28 13:46:38 org.apache.catalina.core.ApplicationContext log
信息: SessionListener: contextInitialized()
2007-5-28 13:46:38 org.apache.catalina.loader.WebappClassLoader validateJarFile
信息: validateJarFile(C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\note\WEB-INF\lib\j2ee.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
2007-5-28 13:46:38 org.apache.catalina.loader.WebappClassLoader validateJarFile
信息: validateJarFile(C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\note\WEB-INF\lib\servlet-api.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
[INFO] 2007-05-28 13:46:39,515 org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization started
[INFO] 2007-05-28 13:46:39,531 org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/note] - Loading Spring root WebApplicationContext
[INFO] 2007-05-28 13:46:39,828 org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]
[INFO] 2007-05-28 13:46:41,125 org.springframework.web.context.support.XmlWebApplicationContext - Bean factory for application context [Root WebApplicationContext]: org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [dataSource,sessionFactory,userDAO,login]; root of BeanFactory hierarchy
[INFO] 2007-05-28 13:46:41,187 org.springframework.web.context.support.XmlWebApplicationContext - 4 beans defined in application context [Root WebApplicationContext]
[INFO] 2007-05-28 13:46:41,218 org.springframework.core.CollectionFactory - JDK 1.4+ collections available
[INFO] 2007-05-28 13:46:41,250 org.springframework.web.context.support.XmlWebApplicationContext - Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@15ad1da]
[INFO] 2007-05-28 13:46:41,265 org.springframework.web.context.support.XmlWebApplicationContext - Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster@1ca1a68]
[INFO] 2007-05-28 13:46:41,296 org.springframework.ui.context.support.UiApplicationContextUtils - Unable to locate ThemeSource with name 'themeSource': using default [org.springframework.ui.context.support.ResourceBundleThemeSource@15d4273]
[INFO] 2007-05-28 13:46:41,312 org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in factory [org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [dataSource,sessionFactory,userDAO,login]; root of BeanFactory hierarchy]
[INFO] 2007-05-28 13:46:41,593 org.hibernate.cfg.Environment - Hibernate 3.0.5
[INFO] 2007-05-28 13:46:41,625 org.hibernate.cfg.Environment - hibernate.properties not found
[INFO] 2007-05-28 13:46:41,625 org.hibernate.cfg.Environment - using CGLIB reflection optimizer
[INFO] 2007-05-28 13:46:41,640 org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
[INFO] 2007-05-28 13:46:42,625 org.hibernate.cfg.HbmBinder - Mapping class: domain.user.User -> user
[INFO] 2007-05-28 13:46:42,718 org.springframework.orm.hibernate3.LocalSessionFactoryBean - Building new Hibernate SessionFactory
[INFO] 2007-05-28 13:46:42,718 org.hibernate.cfg.Configuration - processing extends queue
[INFO] 2007-05-28 13:46:42,718 org.hibernate.cfg.Configuration - processing collection mappings
[INFO] 2007-05-28 13:46:42,718 org.hibernate.cfg.Configuration - processing association property references
[INFO] 2007-05-28 13:46:42,734 org.hibernate.cfg.Configuration - processing foreign key constraints
[INFO] 2007-05-28 13:46:42,968 org.hibernate.connection.ConnectionProviderFactory - Initializing connection provider: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider
[INFO] 2007-05-28 13:46:43,546 org.hibernate.cfg.SettingsFactory - RDBMS: MySQL, version: 5.0.22-community-nt
[INFO] 2007-05-28 13:46:43,546 org.hibernate.cfg.SettingsFactory - JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.1.10 ( $Date: 2005/05/19 15:52:23 $, $Revision: 1.1.2.2 $ )
[INFO] 2007-05-28 13:46:43,640 org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.MySQLDialect
[INFO] 2007-05-28 13:46:43,671 org.hibernate.transaction.TransactionFactoryFactory - Using default transaction strategy (direct JDBC transactions)
[INFO] 2007-05-28 13:46:43,687 org.hibernate.transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
[INFO] 2007-05-28 13:46:43,703 org.hibernate.cfg.SettingsFactory - Automatic flush during beforeCompletion(): disabled
[INFO] 2007-05-28 13:46:43,703 org.hibernate.cfg.SettingsFactory - Automatic session close at end of transaction: disabled
[INFO] 2007-05-28 13:46:43,703 org.hibernate.cfg.SettingsFactory - JDBC batch size: 15
[INFO] 2007-05-28 13:46:43,703 org.hibernate.cfg.SettingsFactory - JDBC batch updates for versioned data: disabled
[INFO] 2007-05-28 13:46:43,718 org.hibernate.cfg.SettingsFactory - Scrollable result sets: enabled
[INFO] 2007-05-28 13:46:43,718 org.hibernate.cfg.SettingsFactory - JDBC3 getGeneratedKeys(): enabled
[INFO] 2007-05-28 13:46:43,718 org.hibernate.cfg.SettingsFactory - Connection release mode: on_close
[INFO] 2007-05-28 13:46:43,718 org.hibernate.cfg.SettingsFactory - Maximum outer join fetch depth: 2
[INFO] 2007-05-28 13:46:43,718 org.hibernate.cfg.SettingsFactory - Default batch fetch size: 1
[INFO] 2007-05-28 13:46:43,734 org.hibernate.cfg.SettingsFactory - Generate SQL with comments: disabled
[INFO] 2007-05-28 13:46:43,734 org.hibernate.cfg.SettingsFactory - Order SQL updates by primary key: disabled
[INFO] 2007-05-28 13:46:43,734 org.hibernate.cfg.SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
[INFO] 2007-05-28 13:46:43,750 org.hibernate.hql.ast.ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory
[INFO] 2007-05-28 13:46:43,750 org.hibernate.cfg.SettingsFactory - Query language substitutions: {}
[INFO] 2007-05-28 13:46:43,750 org.hibernate.cfg.SettingsFactory - Second-level cache: enabled
[INFO] 2007-05-28 13:46:43,750 org.hibernate.cfg.SettingsFactory - Query cache: disabled
[INFO] 2007-05-28 13:46:43,750 org.hibernate.cfg.SettingsFactory - Cache provider: org.hibernate.cache.EhCacheProvider
[INFO] 2007-05-28 13:46:43,781 org.hibernate.cfg.SettingsFactory - Optimize cache for minimal puts: disabled
[INFO] 2007-05-28 13:46:43,781 org.hibernate.cfg.SettingsFactory - Structured second-level cache entries: disabled
[INFO] 2007-05-28 13:46:43,812 org.hibernate.cfg.SettingsFactory - Echoing all SQL to stdout
[INFO] 2007-05-28 13:46:43,812 org.hibernate.cfg.SettingsFactory - Statistics: disabled
[INFO] 2007-05-28 13:46:43,812 org.hibernate.cfg.SettingsFactory - Deleted entity synthetic identifier rollback: disabled
[INFO] 2007-05-28 13:46:43,812 org.hibernate.cfg.SettingsFactory - Default entity-mode: pojo
[INFO] 2007-05-28 13:46:44,218 org.hibernate.impl.SessionFactoryImpl - building session factory
[WARN] 2007-05-28 13:46:44,250 net.sf.ehcache.config.Configurator - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/C:/Program%20Files/Apache%20Software%20Foundation/Tomcat%205.5/webapps/note/WEB-INF/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
[INFO] 2007-05-28 13:46:45,484 org.hibernate.impl.SessionFactoryObjectFactory - Not binding factory to JNDI, no JNDI name configured
[INFO] 2007-05-28 13:46:45,484 org.hibernate.impl.SessionFactoryImpl - Checking 0 named queries
[INFO] 2007-05-28 13:46:45,609 org.springframework.web.context.ContextLoader - Using context class [org.springframework.web.context.support.XmlWebApplicationContext] for root WebApplicationContext
[INFO] 2007-05-28 13:46:45,625 org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization completed in 6110 ms
2007-5-28 13:46:45 org.apache.catalina.core.ApplicationContext log
信息: ContextListener: contextInitialized()
2007-5-28 13:46:45 org.apache.catalina.core.ApplicationContext log
信息: SessionListener: contextInitialized()
2007-5-28 13:46:46 org.apache.coyote.http11.Http11AprProtocol start
信息: Starting Coyote HTTP/1.1 on http-8080
2007-5-28 13:46:46 org.apache.coyote.ajp.AjpAprProtocol start
信息: Starting Coyote AJP/1.3 on ajp-8009
2007-5-28 13:46:46 org.apache.catalina.storeconfig.StoreLoader load
信息: Find registry server-registry.xml at classpath resource
2007-5-28 13:46:46 org.apache.catalina.startup.Catalina start
信息: Server startup in 10172 ms
这是信息,不知道为什么还是不行
2 楼
raybb
2007-05-28
jessdy 写道
userDao为空,貌似没注入?Debug一下?
确实没注入进去 不知道为什么?而且new一个userDAO的话,提示dao里的方法有问题,可是写了个测试类,dao方法没问题,很是不解
1 楼
jessdy
2007-05-28
userDao为空,貌似没注入?Debug一下?
相关推荐
在Java Web应用中,尤其是基于Spring框架的项目里,有时候我们需要在非Action(控制器)类中访问业务逻辑层(DAO层)。为了实现这一目标,Spring提供了一种方法来让我们在非Action类中获取到ApplicationContext上...
在Struts+DAO模式下,我们需要定义ActionForm来接收用户的输入,然后由Action负责调用DAO层进行数据验证。 - **ActionForm**:定义`LoginForm.java`类继承自`ActionForm`,用于存储用户的输入信息。 - **Action**:...
如果在页面中出现空指针异常,通常意味着某个预期被注入的对象为null。 可能的错误原因及解决方案: 1. **配置错误**:检查Spring的配置文件(如`applicationContext.xml`),确保所有需要被注入的对象(如Service...
5. **前端展示**: 最后,在前端页面中通过Struts Action调用DAO层的方法来获取分页后的数据,并将其展示给用户。 #### 总结 本文档详细介绍了如何使用配置文件的方式完成DAO层的封装以及分页功能的实现,并实现了...
当用户提交登录表单时,Action类会调用DAO层来验证用户的信息是否正确。 ```java public class LoginAction extends Action { private String username; private String password; private UserDAO userDAO; ...
错误提示为“Attribute 'calss' 'class' is not allowed to appear in element 'bean'”,这表明在定义Spring的bean元素时,出现了拼写错误('calss'应为'class')。这会导致Spring容器无法正确解析配置文件,进而...
《医院管理系统前台MVC+DAO实现详解》 在IT行业中,设计并实现一套高效、稳定的管理系统是至关重要的,尤其在医疗领域,一个完善的医院管理系统能够极大地提升医疗服务的效率与质量。本文将深入探讨如何运用MVC...
17. DAO类的实例化问题:在Action中调用DAO类时,如果没有重新实例化,可能导致共享状态错误,需确保每次调用都创建新的DAO实例。 18. NullPointerException:`java.lang.NullPointerException`是Java中最常见的...
- **执行逻辑**:此方法作为控制器的核心入口,根据`action`参数的不同值调用不同的业务处理方法。 - **参数解析**:通过`request.getParameter("action")`获取用户提交的操作类型。 ##### 3.3 checkMember方法 ``...
在Struts2中,可以使用Action类来调用这些DAO方法。例如,一个简单的DAO方法用于获取所有数据: ```java public List<User> getAllUsers() { List<User> users = new ArrayList(); Connection conn = null; ...
// 调用DAO的update方法 break; case "select": // 调用DAO的select方法 break; default: // 处理其他情况 } // 设置响应,可能需要重定向或转发到另一个页面 } ``` 以上就是在Servlet中使用JDBC连接...
- **空指针异常**:可能是由于Spring配置不完整,导致Action或Service没有被正确注入。检查XML配置文件,确保所有bean都被定义和关联。 - **数据库连接问题**:确认Hibernate的配置文件(如`hibernate.cfg.xml`)...
- 在业务逻辑实现类`BookService.java`中,调用DAO层的方法,直接返回`bookDAO.getRequiredBookByName(name)`的结果,实现了业务逻辑的封装。 3. **Action(动作)层**: - 在Struts2框架的配置文件`struts.xml`...
5. **错误信息处理**:在资源文件中配置错误信息,如`ApplicationResources.properties`文件中配置`username.null=\u7528\u6237\u540d\u4e0d\u80fd\u4e3a\u7a7a`等,确保用户能看到有意义的错误提示。 6. **动态...
- **Action类型替换**: 替换默认的Action类型,使其能够调用Spring管理的Bean。 #### 三、技术难点与解决方案 - **事务一致性**: 在整合过程中,确保所有数据操作都在同一个事务内完成,避免出现脏读等问题。 - **...
最后,你需要一个Servlet或者控制器来处理JSP页面提交的请求,并调用DAO方法进行验证。例如,你可以创建一个`LoginServlet`: ```java @WebServlet("/login") public class LoginServlet extends HttpServlet { @...
在 DAO 中,我们需要使用 PreparedStatement 来执行 SQL 语句,並insert一个空 BLOB 对象,然后 Update 这个空对象。 在 Struts 项目中,我们可以使用以下代码来实现大对象的上传: ```java // 新增 if (action...
为保持良好的代码组织,可以将`UserDAO.java`移动到新创建的`dao`包中,并更新`applicationContext.xml`以指向正确的包路径。同时,需要修改映射文件,移除`catalog`属性,以避免SQL异常。 4. 建立业务逻辑层。创建...