struts2与spring 结合时一些问题
来源:互联网 发布:java调用linux命令 编辑:程序博客网 时间:2024/06/05 02:26
1,spring自动生成action 的实例,前提要在web.xml中配置spring的监听器以及加入struts2-spring-plugin.jar包
- <listener>
- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
- </listener>
- <context-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>classpath:beans.xml</param-value>
- </context-param>
将struts.xml配置的action命名为和Action类名字相同@Component("action命名");@Scope("prototype")不要忘记,每一个产生的action对象都是新的;
其实在action名字相同的情况下上边两个注解可以都不写,默认的scope就是prototype;
2,默认情况下action中的属性再不用注解的情况下都会自动注入,前提是属性名称与类名的@Component("命名")相同,属性名称首字母小写,名称不相同的情况下需要用注解@Resource(name=""),一般常用在setter方法上;
3,异常:could not initialize proxy - no Session...
在web.xml中struts之前配置:
<filter>
<filter-name>opensession</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>opensession</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-name>opensession</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>opensession</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
这样session一旦打开就会等到我们访问完之后才会关闭,把session打开的时间一直延续到View层。
使用load时需要需要上述操作,使用get时不需要
4,总结spring容器中装的bean是service和dao;action的产生完全由struts2-spring-plugin产生,action类中不需要写注解,属性名称要与类名的@Component("命名")相同;
5,如果在bean.xml中没有配置事务,如果在web.xml配置了OpenSessionInView,则认为事务是只读的(readOnly),则不允许做增删改的操作;
所以正常情况下两者都应该配置;
6,spring中一个解决编码问题的过滤器也很好用,在web.xml中配置
- <filter>
- <filter-name>EncodingFilter</filter-name>
- <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
- <init-param>
- <param-name>encoding</param-name>
- <param-value>gbk</param-value> //大小写不所谓
- </init-param>
- </filter>
- <filter-mapping>
- <filter-name>EncodingFilter</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
7,关于spring管理action的官方文档解释:在action类上边配置@Component('"action")@Scope("prototype");在struts.xml配置文件中action一行的class="action" ;这样action就像其他普通类一样被spring管理。当然action的属性都需要@Resource()注解。
- struts2与spring 结合时一些问题
- struts2与spring结合
- struts2与spring结合
- Struts2 与spring结合
- Spring如何与struts2结合
- Spring如何与struts2结合
- struts2结合spring json序列化问题
- struts2与spring结合后的生命周期
- Struts2与Spring结合的jar包
- spring mvc的SimpleFormController与AJAX结合遇到的一些问题
- spring,mybatis,struts2结合
- spring.net与OracleODP结合时发生的版本问题
- Struts2和Spring整合中的一些问题
- struts2与spring、jdbc结合以及AOP事务管理的配置
- Spring AOP与struts1.x,struts2.x的结合
- struts2与dao结合
- struts2与ajax结合
- jfreechart与struts2结合
- css firefox火狐浏览器下的兼容性问题
- linux rtc驱动
- resultSetType resultSetConcurrency
- android仿iPhone滚轮控件实现及源码分析
- 黑马程序员---ADO.Net学习小结
- struts2与spring 结合时一些问题
- Google Syntax Highlighter for WordPress的使用
- 为WordPress编辑器添加WP-Syntax按钮
- 三、数据完整性
- 什么叫oracle聚合函数 http://zhidao.baidu.com/question/238535989.html
- CPropertySheet失去焦点后程序失去响应
- OpenProcess使用PROCESS_ALL_ACCESS返回ERROR_ACCESS_DENIED
- Failed to create the Java Virtual Machine
- 安装STEP 7 MicroWIN SP9 V4.0