Hibernate+spring+struts2+orcale
我也不知道这是什么问题-------------------------------------------------applicationContext.xml<?x...
我也不知道这是什么问题
-------------------------------------------------
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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="oracle.jdbc.driver.OracleDriver">
</property>
<property name="url"
value="jdbc:oracle:thin:@192.168.1.12:1521:LBTERP">
</property>
<property name="username" value="crmdev"></property>
<property name="password" value="crmdev"></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.dialect">
org.hibernate.dialect.Oracle9Dialect
</prop>
<prop key="hibernate.show_sql">
true
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/lbt/pojo/TRole.hbm.xml</value>
<value>com/lbt/pojo/TRoleMenu.hbm.xml</value>
<value>com/lbt/pojo/TRecord.hbm.xml</value>
<value>com/lbt/pojo/TEmployee.hbm.xml</value>
<value>com/lbt/pojo/TFlow.hbm.xml</value>
<value>com/lbt/pojo/TContact.hbm.xml</value>
<value>com/lbt/pojo/TMerchant.hbm.xml</value>
<value>com/lbt/pojo/TMenu.hbm.xml</value></list>
</property>
</bean>
<bean id="temployeeDao" class="com.lbt.dao.TEmployeeDao">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
</beans>
-----------------------------
error
java.lang.NullPointerException
com.lbt.action.LoginAction.execute(LoginAction.java:49)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source) 展开
-------------------------------------------------
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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="oracle.jdbc.driver.OracleDriver">
</property>
<property name="url"
value="jdbc:oracle:thin:@192.168.1.12:1521:LBTERP">
</property>
<property name="username" value="crmdev"></property>
<property name="password" value="crmdev"></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.dialect">
org.hibernate.dialect.Oracle9Dialect
</prop>
<prop key="hibernate.show_sql">
true
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/lbt/pojo/TRole.hbm.xml</value>
<value>com/lbt/pojo/TRoleMenu.hbm.xml</value>
<value>com/lbt/pojo/TRecord.hbm.xml</value>
<value>com/lbt/pojo/TEmployee.hbm.xml</value>
<value>com/lbt/pojo/TFlow.hbm.xml</value>
<value>com/lbt/pojo/TContact.hbm.xml</value>
<value>com/lbt/pojo/TMerchant.hbm.xml</value>
<value>com/lbt/pojo/TMenu.hbm.xml</value></list>
</property>
</bean>
<bean id="temployeeDao" class="com.lbt.dao.TEmployeeDao">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
</beans>
-----------------------------
error
java.lang.NullPointerException
com.lbt.action.LoginAction.execute(LoginAction.java:49)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source) 展开
1个回答
展开全部
出现空指针异常了,看看struts2中的execute方法是不是写的有问题!问题可能发生在LoginAction这个类中。
SSH整合步骤:(看下配置是不是有问题)
1. 添加Spring 2.0的Libraries
选择以下4个jar,并配置到/WEB-INF/lib下
Spring2.0 AOP Libraries
Spring2.0 Core Libraries
Spring2.0 Persistence Core Libraries
Spring2.0 WEb Libraries
同时,将applicationContext.xml配置到WEB/INF下面。
2. 添加Hibernate 3.0的Libraries
选择以下2个jar,并配置到/WEB-INF/lib下
Hibernate 3.0 Core Libraries
hibernate 3.0 Advanced Support Libraries
同时Hibernate的文件选择合并到applicationContext.xml(即不单独创建hibernate的配置文件,而是将其作为资源文件整合到applicationContext.xml中)
3. 添加commons-pool-1.4.jar和commons-dbcp-1.2.2.jar两个jar到lib下,以消除applicationContext.xml中找不到class的的错误
4. 添加struts2的五个jar到lib下
commons-logging-1.0.4.jar
freemarker-2.3.8.jar
ognl-2.6.11.jar
xwork-2.0.5.jar
struts-core-1.3.5.jar
注意:由于要整合Spring,还需要添加struts2-spring-plugin-2.0.11.2.jar
5. 配置web.xml
5.1 配置spring的应用上下文
<!-- spring的应用上下文 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext*.xml</param-value>
</context-param>
5.2 配置struts2的过滤器
<!-- struts2 过滤器 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
5.3 配置spring的监听器,以便在启动时就自动加载spring的配置
<!-- spring的监听器,以便在启动时就自动加载spring的配置 -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
5.4 配置OpenSessionInViewFilter过滤器,处理事务
<!-- OpenSessionInViewFilter过滤器 -->
<filter>
<filter-name>lazyLoadingFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>lazyLoadingFilter</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
6. 配置struts.xml
6.1 添加一常量,将action交予Spring处理
<constant name="struts.objectFactory" value="spring"></constant>
6.2 配置action
7. 将struts.xml中的action注册到applicationContext.xml中
SSH整合步骤:(看下配置是不是有问题)
1. 添加Spring 2.0的Libraries
选择以下4个jar,并配置到/WEB-INF/lib下
Spring2.0 AOP Libraries
Spring2.0 Core Libraries
Spring2.0 Persistence Core Libraries
Spring2.0 WEb Libraries
同时,将applicationContext.xml配置到WEB/INF下面。
2. 添加Hibernate 3.0的Libraries
选择以下2个jar,并配置到/WEB-INF/lib下
Hibernate 3.0 Core Libraries
hibernate 3.0 Advanced Support Libraries
同时Hibernate的文件选择合并到applicationContext.xml(即不单独创建hibernate的配置文件,而是将其作为资源文件整合到applicationContext.xml中)
3. 添加commons-pool-1.4.jar和commons-dbcp-1.2.2.jar两个jar到lib下,以消除applicationContext.xml中找不到class的的错误
4. 添加struts2的五个jar到lib下
commons-logging-1.0.4.jar
freemarker-2.3.8.jar
ognl-2.6.11.jar
xwork-2.0.5.jar
struts-core-1.3.5.jar
注意:由于要整合Spring,还需要添加struts2-spring-plugin-2.0.11.2.jar
5. 配置web.xml
5.1 配置spring的应用上下文
<!-- spring的应用上下文 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext*.xml</param-value>
</context-param>
5.2 配置struts2的过滤器
<!-- struts2 过滤器 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
5.3 配置spring的监听器,以便在启动时就自动加载spring的配置
<!-- spring的监听器,以便在启动时就自动加载spring的配置 -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
5.4 配置OpenSessionInViewFilter过滤器,处理事务
<!-- OpenSessionInViewFilter过滤器 -->
<filter>
<filter-name>lazyLoadingFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>lazyLoadingFilter</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
6. 配置struts.xml
6.1 添加一常量,将action交予Spring处理
<constant name="struts.objectFactory" value="spring"></constant>
6.2 配置action
7. 将struts.xml中的action注册到applicationContext.xml中
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询