开门见山
1.
版本 spring 4.0.0
时间:2015-09-04
症状:No mapping found for HTTP request with URI [/hello/] in DispatcherServlet with name 'dispatcher'
Controoler层代码
@Controller
public class HelloTestController {
@RequestMapping("/hello")
public String hello(@RequestParam(value="name", required=false, defaultValue="Worlde") String name, Model model){
System.out.println("Controller start=================>");
model.addAttribute("name", name);
return "helloSpring";
}
}
解决:在application.xml 配置文件中,增加
<mvc:annotation-driven />
*备注:if you use annotation you must configure following setting<
mvc:annotation-driven
/>
2.
版本:Spring4.0.0
时间:2015-09-04
症状:
nested exception is java.io.FileNotFoundException: D:\workspace\SpringMvcHello\src\main\webapp\WEB-INF\classes\config\application.xml (系统找不到指定的路径。)
在src/mian/resource/config 目录下已经配置了application.xml
web.xml配置:
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:config/application.xml</param-value>
</context-param>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:config/application.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
解决:
这个感觉是tomcat 6 和 tomcat 7的差别
tomcat6 不会报这个错,tomcat7会
但tomcat的@RequestMapping声明又有所不同
@Controller
public class HelloMaven {
@RequestMapping(value="hello")
public String hello(@RequestParam(value="name", required=false, defaultValue="Worlde") String name, Model model){
System.out.println("Controller start=================>");
model.addAttribute("name", name);
return "helloSpring";
}
}
*备注:
3.
版本 Spring2.5.6
时间:2017-04-29
症状;
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
ContextLoaderListener类位于 spring-web.jar 中,spring-web.jar 已经添加
错误原因:
进入到tomcat的部署路径.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\下检查了一下,发现工程部署后在WEB-INF文件夹下没有生成lib目录,正常情况下,会生成lib目录并把工程的所有依赖jar包都部署到该目录下。
解决方案:
1.右键点击项目--选择Properties
选择Deployment Assembly,在右边点击Add按钮,在弹出的窗口中选择Java Build Path Entries
2.点击Next,选择工程/WEB-INF/lib/下所有jar包
3.点击Finish,然后可以看到已经把lib下jar包添加到Web应用结构中了
4.
版本 spring2.5 struts2.1 hibernate3.2
时间 2017-04-30
症状:
SSH2整合项目遇到:
No result defined for action cn.sshdemo.action.UserAction and result success
【错误原因】
struts在spring配置文件中没有找到action对应的类名称。
解决:
把struts.xml中action 里 的class 名称改成和spring配置文件一致的才行。
spring配置文件
<bean id="userAction" class="cn.sshdemo.action.UserAction">
<property name="userService" ref="userService"></property>
</bean>
struts配置文件
<action name="*" class="userAction" method="{1}">
5.
SSH2项目注意事项
①需要 struts2-spring-plugin.jar
配置文件 web.xml
<!-- 下面的代码为了在web中使用spring,还要加载spring 的配置文件,所以要指定application.xml文件的位置-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
<init-param>
<param-name>config</param-name>
<param-value>struts-default.xml,struts-plugin.xml,../struts.xml</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 为了让web应用能加载spring,设置一个侦听,通过这样一个监听器,一启动WEB应用它自动根据上面设置好的配置文件的位置把配置文件加载到内存中,为进一步使用spring中的bean做好准备 -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
6.
版本 spring2.5 struts2.1 hibernate3.2
时间 2017/04/30
症状:
There is no Action mapped for namespace / and action name list
【错误原因】
SSH2没有找到struts.xml
①struts.xml文件名错误。一定要注意拼写问题;
②struts.xml文件放置路径错误。一定要将此文件放置在src目录下。编译成功后,要确认是否编译到classes目录中;
③struts.xml文件内容错误。
参考
http://www.cnblogs.com/gulvzhe/archive/2011/11/21/2256632.html
【解决方案】
struts2的控制器org.apache.struts2.dispatcher.FilterDispatcher上说,这个类默认的是导入/classes 下的struts.xml。
7.
版本 spring2.5 struts2.1 hibernate3.2
时间 2017/04/30
症状:
No mapping found for dependency [type=com.opensymphony.xwork2.ObjectFactory, name='default'] in public void com.opensymphony.xwork2.config.
【错误原因】
struts.xml 中没有引入struts-default.xml文件。
【解决方案】
<init-param>
<param-name>config</param-name>
<param-value>struts-default.xml,struts-plugin.xml,../struts.xml</param-value>
</init-param>
10.
Struts知识点
①
http://www.iteye.com/topic/1143506
SSH框架整合配置所需JAR包(SSH整合)
②
http://www.cnblogs.com/leonkobe/p/5672567.html
Struts2 中的配置文件 package name 、namespace 以及 对象方法调用
http://blog.csdn.net/zhubinqiang/article/details/8498808
SSH整合 简单的增删改查