在实验室写了两年代码,框架用过好几个,但是一般都是实验室使用的比较成熟的框架,不需要自己去搭建,只需要往里面写代码就是了,因此到现在框架的搭建对于我来说,还是一件比较陌生的事情,虽然之前的框架在使用的时候都会看一下它的配置,但是真正自己搭建的时候还是遇到了很多问题。
我在网上找了一个比较详细的SSI框架搭建的教程,开始按照上面的步骤一点一点的开始做,可以说是完全按照上面的内容来的,但是等搭完以后一运行,果然是不行的,因此开始了我漫长的调试阶段。
我遇到的第一个问题,是由于我之前正在使用另一个工具调试项目,因此8080端口被占用,换了一个端口号仍然不行,最后还是结束掉那个进程才得以解决。
下面是第二个问题:
严重: Dispatcher initialization failed
Unable to load configuration. - package - file:/F:/学习软件/apache-tomcat-6.0.29-windows-x86/apache-tomcat-6.0.29/webapps/SSITest/WEB-INF/classes/struts.xml:10:56
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:69)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:371)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:415)
at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:69)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:51)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:295)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:422)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:115)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4001)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4651)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:546)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1041)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:964)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:502)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1277)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:321)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)
at org.apache.catalina.core.StandardService.start(StandardService.java:519)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
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.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: Unable to find interceptor class referenced by ref-name parasPrepareParamsStack - package - file:/F:/学习软件/apache-tomcat-6.0.29-windows-x86/apache-tomcat-6.0.29/webapps/SSITest/WEB-INF/classes/struts.xml:10:56
at com.opensymphony.xwork2.config.providers.InterceptorBuilder.constructInterceptorReference(InterceptorBuilder.java:63)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.buildFullActionConfig(DefaultConfiguration.java:341)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.buildRuntimeConfiguration(DefaultConfiguration.java:284)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.rebuildRuntimeConfiguration(DefaultConfiguration.java:146)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:220)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:66)
... 31 more
2012-6-20 18:44:09 org.apache.catalina.core.StandardContext filterStart
严重: Exception starting filter struts2
Unable to load configuration. - package - file:/F:/学习软件/apache-tomcat-6.0.29-windows-x86/apache-tomcat-6.0.29/webapps/SSITest/WEB-INF/classes/struts.xml:10:56
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:428)
at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:69)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:51)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:295)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:422)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:115)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4001)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4651)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:546)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1041)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:964)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:502)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1277)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:321)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)
at org.apache.catalina.core.StandardService.start(StandardService.java:519)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
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.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: Unable to load configuration. - package - file:/F:/学习软件/apache-tomcat-6.0.29-windows-x86/apache-tomcat-6.0.29/webapps/SSITest/WEB-INF/classes/struts.xml:10:56
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:69)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:371)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:415)
... 29 more
Caused by: Unable to find interceptor class referenced by ref-name parasPrepareParamsStack - package - file:/F:/学习软件/apache-tomcat-6.0.29-windows-x86/apache-tomcat-6.0.29/webapps/SSITest/WEB-INF/classes/struts.xml:10:56
at com.opensymphony.xwork2.config.providers.InterceptorBuilder.constructInterceptorReference(InterceptorBuilder.java:63)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.buildFullActionConfig(DefaultConfiguration.java:341)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.buildRuntimeConfiguration(DefaultConfiguration.java:284)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.rebuildRuntimeConfiguration(DefaultConfiguration.java:146)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:220)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:66)
... 31 more
2012-6-20 18:44:09 org.apache.catalina.core.StandardContext start
严重: Error filterStart
2012-6-20 18:44:09 org.apache.catalina.core.StandardContext start
严重: Context [/SSITest] startup failed due to previous errors
2012-6-20 18:44:09 org.apache.catalina.core.ApplicationContext log
信息: Closing Spring root WebApplicationContext
2012-6-20 18:44:09 org.springframework.context.support.AbstractApplicationContext doClose
信息: Closing org.springframework.web.context.support.XmlWebApplicationContext@e391c4: display name [Root WebApplicationContext]; startup date [Wed Jun 20 18:44:02 CST 2012]; root of context hierarchy
2012-6-20 18:44:09 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
信息: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1eef2c: defining beans [dataSource,sqlMapClient,transactionManager,userDao,userService,LoginAction]; root of factory hierarchy
2012-6-20 18:44:09 org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
严重: The web application [/SSITest] created a ThreadLocal with key of type [null] (value [com.opensymphony.xwork2.inject.ContainerImpl$10@db4c8d]) and a value of type [java.lang.Object[]] (value [[Ljava.lang.Object;@17ed710]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
2012-6-20 18:44:09 org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
严重: The web application [/SSITest] created a ThreadLocal with key of type [null] (value [com.opensymphony.xwork2.inject.ContainerImpl$10@598a5d]) and a value of type [java.lang.Object[]] (value [[Ljava.lang.Object;@8b1323]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
这个问题真是让我纠结了半天,我在网上查到了有关这个问题的解决方案,是由于jar包的问题,但是当我按照解决方法重新导入jar包以后,问题依然存在,既然没有找到适合的解决方法,我只能自己来试一下,根据出错的信息,我定位到struts2.xml文件下面先把struts2.xml贴出来:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.objectTypeDeterminer" value="notiger" />
<constant name="struts.objectFactory.spring.autoWire" value="name" />
<constant name="struts.objectFactory" value="spring" />
<package name="struts2" extends="struts-default">
<default-interceptor-ref name="paramsPrepareParamsStack"/>
<default-class-ref class="com.opensymphony.xwork2.ActionSupport"/>
<action name="login" class="LoginAction">
<result name="success">/success.jsp</result>
<result name="input">/login.jsp</result>
</action>
</package>
<include file="com/zhouqian/bean/user.xml" />
</struts>
问题就出在红色位置的那一行,我查了一下其他的配置SSI框架的教程,发现很多都没有这一句,因此我尝试把它注掉,运行,没想到竟然没有问题了,真是意外惊喜,我查了下,这是一个struts的拦截器,但是为什么这里错了,我还没有搞清楚。
当我在下面添加了 <default-class-ref class="com.opensymphony.xwork2.ActionSupport"/>以后运行不再有错,需要查看相关书籍确定一下。
下面是我的整个框架的配置:
首先是项目的整体的结构图:
![](https://img-my.csdn.net/uploads/201206/20/1340189795_2931.jpg)
Login.java
/*
zhouqian
Jun 20, 2012
*/
package com.zhouqian.action;
import java.util.List;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;
import com.zhouqian.bean.User;
import com.zhouqian.service.IUserService;
public class Login extends ActionSupport implements ModelDriven<User>,Preparable {
private IUserService userService=null;
private String id;
private int pageIndex=1;
private String pageBar;
private List<User> list;
private User user;
public void prepare()throws Exception{
if(id==null||id.length()==0){
user=new User();
}else{
user=this.getUserService().getUserById(Integer.parseInt(id));
}
}
public String execute() throws Exception{
if(getUserService().isLogin(user)){
return SUCCESS;
}
return INPUT;
}
public IUserService getUserService() {
return userService;
}
public void setUserService(IUserService userService) {
this.userService = userService;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public int getPageIndex() {
return pageIndex;
}
public void setPageIndex(int pageIndex) {
this.pageIndex = pageIndex;
}
public String getPageBar() {
return pageBar;
}
public void setPageBar(String pageBar) {
this.pageBar = pageBar;
}
public List<User> getList() {
return list;
}
public void setList(List<User> list) {
this.list = list;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public User getModel() {
// TODO Auto-generated method stub
return user;
}
}
User.java
/*
zhouqian
Jun 20, 2012
*/
package com.zhouqian.bean;
public class User {
private int id;
private String username;
private String password;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
user.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="User">
<typeAlias alias="user" type="com.zhouqian.bean.User" />
<select id="getUserById" parameterClass="int" resultClass="user">
select * from user where id=#id#
</select>
<select id="checkUser" parameterClass="user" resultClass="user">
select * from user where username=#username# and
password=#password#
</select>
</sqlMap>
IUserDao.java
/*
zhouqian
Jun 20, 2012
*/
package com.zhouqian.dao;
import java.util.List;
import com.zhouqian.bean.User;
public interface IUserDao {
public User getUserById(Integer id);
public boolean isLogin(User user);
}
UserDao.java
/*
zhouqian
Jun 20, 2012
*/
package com.zhouqian.dao;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.zhouqian.bean.User;
public class UserDao implements IUserDao {
private SqlMapClient sqlMapClient=null;
public User getUserById(Integer id){
User user=null;
try{
user=(User)sqlMapClient.queryForObject("getUserById", id);
return user;
}catch(Exception e){
e.getStackTrace();
}
return user;
}
public boolean isLogin(User user){
try{
User u=(User)sqlMapClient.queryForObject("checkUser", user);
if(u!=null){
return true;
}
}catch(Exception e){
e.getStackTrace();
}
return false;
}
public SqlMapClient getSqlMapClient() {
return sqlMapClient;
}
public void setSqlMapClient(SqlMapClient sqlMapClient) {
this.sqlMapClient = sqlMapClient;
}
}
IUserService.java
/*
zhouqian
Jun 20, 2012
*/
package com.zhouqian.service;
import com.zhouqian.bean.User;
public interface IUserService {
public User getUserById(Integer id);
public boolean isLogin(User user);
}
UserService.java
/*
zhouqian
Jun 20, 2012
*/
package com.zhouqian.service;
import com.zhouqian.bean.User;
import com.zhouqian.dao.IUserDao;
public class UserService implements IUserService {
private IUserDao userDao=null;
public void setUserDao(IUserDao userDao) {
this.userDao = userDao;
}
public User getUserById(Integer id){
return userDao.getUserById(id);
}
public boolean isLogin(User user){
return userDao.isLogin(user);
}
}
sqlMapConfig.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMapConfig PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
<settings cacheModelsEnabled="true" enhancementEnabled="true"
lazyLoadingEnabled="true" maxRequests="32" maxSessions="10"
maxTransactions="5" useStatementNamespaces="false" />
<sqlMap resource="com/zhouqian/bean/user.xml" />
</sqlMapConfig>
struts.properties
struts.devMode=true
struts.configuration.xml.reload=true
struts.locale=zh_CN
struts.il8n.encoding=UTF-8
struts.objectFactory=spring
struts.enable.DynamicMethodInvocation = false
struts.objectTypeDeterminer = notiger
struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.objectTypeDeterminer" value="notiger" />
<constant name="struts.objectFactory.spring.autoWire" value="name" />
<constant name="struts.objectFactory" value="spring" />
<package name="struts2" extends="struts-default">
<!-- <default-interceptor-ref name="parasPrepareParamsStack"/>-->
<action name="login" class="LoginAction">
<result name="success">/success.jsp</result>
<result name="input">/login.jsp</result>
</action>
</package>
<include file="com/zhouqian/bean/user.xml" />
</struts>
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans default-autowire="byType"
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:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://127.0.0.1:3306/test"></property>
<property name="username" value="root" />
<property name="password" value="root" />
</bean>
<bean id="sqlMapClient"
class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation">
<value>classpath:sqlMapConfig.xml</value>
</property>
<property name="dataSource" ref="dataSource" />
</bean>
<!-- spring 的事务处理类配置 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource">
<ref local="dataSource" />
</property>
</bean>
<bean id="userDao" class="com.zhouqian.dao.UserDao">
<property name="sqlMapClient" ref="sqlMapClient" />
</bean>
<bean id="userService" class="com.zhouqian.service.UserService">
<property name="userDao" ref="userDao"></property>
</bean>
<bean id="LoginAction" class="com.zhouqian.action.Login">
<property name="userService" ref="userService"></property>
</bean>
</beans>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/applicationContext.xml</param-value>
</context-param>
</web-app>
添加的jar文件如下:
jar包中可能有没有使用到的,还待进一步的缩减。