配置整合DWR3.0和Spring2.5使用annotation注解

本文介绍如何将DWR3.0与Spring2.5框架进行整合,通过使用annotation注解简化配置流程。文章详细展示了如何创建控制器类、配置web.xml以及设置DispatcherServlet。
配置整合DWR3.0和Spring2.5使用annotation注解


这里使用 DWR3.rc1, Spring2.5 and Spring MVC



在Spring2.5中,使用了许多annotation, 新版本的DWR也支持annotation了, 下面看一下配置过程



1. 先写一个Controller


Java代码 复制代码

1. package com.myapp.web.controller;
2.
3. import javax.servlet.http.HttpServletRequest;
4. import org.directwebremoting.annotations.RemoteMethod;
5. import org.directwebremoting.annotations.RemoteProxy;
6. import org.springframework.stereotype.Controller;
7. import org.springframework.web.bind.annotation.RequestMapping;
8.
9. @Controller
10. @RemoteProxy
11. public class UserController {
12.
13. @RemoteMethod
14. public String getUserName(int id) {
15. System.out.println("user id is " + id);
16. return "UserName: " + id;
17. }
18.
19. @RequestMapping("/user/add.do")
20. public String addUser(HttpServletRequest request) {
21. System.out.println("this is action method");
22. return "/user/list.jsp";
23. }
24. }

package com.myapp.web.controller;

import javax.servlet.http.HttpServletRequest;
import org.directwebremoting.annotations.RemoteMethod;
import org.directwebremoting.annotations.RemoteProxy;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RemoteProxy
public class UserController {

@RemoteMethod
public String getUserName(int id) {
System.out.println("user id is " + id);
return "UserName: " + id;
}

@RequestMapping("/user/add.do")
public String addUser(HttpServletRequest request) {
System.out.println("this is action method");
return "/user/list.jsp";
}
}



@RemoteProxy注解告诉DWR,这个Class是我们想暴露出来的。@RemoteMethod注解告诉DWR去暴露这个指定的方法,只有加了RemoteMethod注解的方法会被暴露,其它的不会。

这里也可以使用@RemoteProxy(name="userRemote")的方式指定DWR接口的名字



2. 接下来看web.xml的配置


Xml代码 复制代码

1. <servlet>
2. <servlet-name>action</servlet-name>
3. <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
4. <load-on-startup>1</load-on-startup>
5. </servlet>
6.
7. <context-param>
8. <param-name>contextConfigLocation</param-name>
9. <param-value>/WEB-INF/springconfig/*.xml</param-value>
10. </context-param>
11.
12. <servlet-mapping>
13. <servlet-name>action</servlet-name>
14. <url-pattern>*.do</url-pattern>
15. </servlet-mapping>
16.
17. <servlet-mapping>
18. <servlet-name>action</servlet-name>
19. <url-pattern>/dwr/*</url-pattern>
20. </servlet-mapping>
21.
22. <listener>
23. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
24. </listener>

<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/springconfig/*.xml</param-value>
</context-param>

<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>



注意,这里没有使用org.directwebremoting.spring.DwrSpringServlet或org.directwebremoting.servlet.DwrServlet,并且请注意这里使用spring的dispatcher servlet来映射/dwr/*请求。



3. 最后看针对DispatcherServlet的配置文件action-servlet.xml


Xml代码 复制代码

1. <beans xmlns="http://www.springframework.org/schema/beans"
2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3. xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr"
4. xmlns:context="http://www.springframework.org/schema/context"
5. xsi:schemaLocation="http://www.springframework.org/schema/beans
6. http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
7. http://www.springframework.org/schema/context
8. http://www.springframework.org/schema/context/spring-context-2.5.xsd
9. http://www.directwebremoting.org/schema/spring-dwr
10. http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd"
11. default-autowire="byName">
12.
13. <context:annotation-config />
14.
15. <!-- 注意这里新增加的dwr tag, 为使其生效,文件头中要声明namespace -->
16. <dwr:configuration />
17. <dwr:annotation-config />
18. <dwr:url-mapping />
19.
20. <!-- 部署项目时, 请把debug设为false -->
21. <dwr:controller id="dwrController" debug="true" />
22.
23. <!-- 多个包名用逗号隔开, 但不能有空格 -->
24. <context:component-scan base-package="com.myapp.web.controller" />
25.
26. <!-- order值越小, 优先级越高 -->
27. <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
28. <property name="order" value="1" />
29. </bean>
30. <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping">
31. <property name="order" value="2" />
32. </bean>
33.
34. </beans>

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.directwebremoting.org/schema/spring-dwr
http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd"
default->

<context:annotation-config />

<!-- 注意这里新增加的dwr tag, 为使其生效,文件头中要声明namespace -->
<dwr:configuration />
<dwr:annotation-config />
<dwr:url-mapping />

<!-- 部署项目时, 请把debug设为false -->
<dwr:controller id="dwrController" debug="true" />

<!-- 多个包名用逗号隔开, 但不能有空格 -->
<context:component-scan base-package="com.myapp.web.controller" />

<!-- order值越小, 优先级越高 -->
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="order" value="1" />
</bean>
<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping">
<property name="order" value="2" />
</bean>

</beans>



简单解释一下这些配置

* <dwr:annotation-config /> 要求DWR在Spring容器中检查拥有@RemoteProxy 和 @RemoteMethod注解的类。注意它不会去检查Spring容器之外的类。
* <dwr:url-mapping /> 要求DWR将util.js和engine.js映射到dwrController
* <dwr:controller id="dwrController" debug="true" /> 定义dwrController
* <dwr:configuration /> 此标签在这个例子中不是必须的,如果你想配置Spring容器之外的类,就需要它了。

最后一件事,DWR的测试页面 http://localhost:8080/myapp/dwr 在这里不好用。

请使用 http://localhost:8080/myapp/dwr/test/YOUR-BEAN-NAME 的方式来测试你的DWR接口,

例如这里使用 http://localhost:8080/myapp/dwr/test/UserController



OK 运行测试一下吧
一、 内容概要 本资源提供了一个完整的“金属板材压弯成型”非线性仿真案例,基于ABAQUS/Explicit或Standard求解器完成。案例精确模拟了模具(凸模、凹模)与金属板材之间的接触、压合过程,直至板材发生塑性弯曲成型。 模型特点:包含完整的模具-工件装配体,定义了刚体约束、通用接触(或面面接触)及摩擦系数。 材料定义:金属板材采用弹塑性材料模型,定义了完整的屈服强度、塑性应变等真实应力-应变数据。 关键结果:提供了成型过程中的板材应力(Mises应力)、塑性应变(PE)、厚度变化​ 云图,以及模具受力(接触力)曲线,完整再现了压弯工艺的力学状态。 二、 适用人群 CAE工程师/工艺工程师:从事钣金冲压、模具设计、金属成型工艺分析与优化的专业人员。 高校师生:学习ABAQUS非线性分析、金属塑性成形理论,或从事相关课题研究的硕士/博士生。 结构设计工程师:需要评估钣金件可制造性(DFM)或预测成型回弹的设计人员。 三、 使用场景及目标 学习目标: 掌握在ABAQUS中设置金属塑性成形仿真的全流程,包括材料定义、复杂接触设置、边界条件与载荷步。 学习如何调试分析大变形、非线性接触问题的收敛性技巧。 理解如何通过仿真预测成型缺陷(如减薄、破裂、回弹),并与理论或实验进行对比验证。 应用价值:本案例的建模方法与分析思路可直接应用于汽车覆盖件、电器外壳、结构件等钣金产品的冲压工艺开发与模具设计优化,减少试模成本。 四、 其他说明 资源包内包含参数化的INP文件、CAE模型文件、材料数据参考及一份简要的操作要点说明文档。INP文件便于用户直接修改关键参数(如压边力、摩擦系数、行程)进行自主研究。 建议使用ABAQUS 2022或更高版本打开。显式动力学分析(如用Explicit)对计算资源有一定要求。 本案例为教学与工程参考目的提供,用户可基于此框架进行拓展,应用于V型弯曲
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值