读书人

spring3 + dwr 如何能够配置成功

发布时间: 2012-12-20 09:53:21 作者: rapoo

spring3 + dwr 怎么能够配置成功
在网上搜了两三天了
发现自己总是配不成功
无数个报错信息
好不容易弄了个启动不报错的
可是这回执行的时候报空指针了

目前项目使用的是注解的方式进行操作的
分为按照MVC的模式进行包的划分
数据库用mybatis支持

打算被dwr暴露的类是一个service中的类
该类执行数据库操作时使用了用@Autowired的dao类进行数据库操作

现在需要增加dwr的功能
可是怎么样都配置不成功
有没有可以在这种状况下配置成功啊?

具体的配置说明如下(原有配置,不包含dwr的配置信息):
web-info目录下有system-servlet.xml和web.xml两个文件
以上配置都已经是正常的可以使用的
web.xml


<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>system</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>system</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>

以上是web.xml的部分配置信息,其他信息跟spring无关,故无需提供


system-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2010 The myBatis Team

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd


http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<!-- 数据源配置已经忽略 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<context:component-scan
base-package="XXXXXXXX" />

<!-- enable autowire -->
<context:annotation-config />
<!-- 会话工厂 -->
<bean id="sqlSessionFactory"
class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="typeAliasesPackage"
value="XXXXXX" />
</bean>

<!-- scan for mappers and let them be autowired -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage"
value="XXXXXX" />
</bean>
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/view/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>


无关的代码被屏蔽了

jar的加载使用MAVEN进行控制



系统访问过程是
访问XXXX.html后
系统提交访问到对应的Controllor(注解为@Controller)中
Controllor访问已经被@Autowired的对应的Service类的对应方法
Service类已经被注解为@Service
Service类中含有被@Autowired的mapper
mapper对应着mybatis的各种操作

以上过程正确且可行

现在需要添加dwr的支持
谁能告诉告诉我怎么配置能够成功?
谢谢啦先
[最优解释]
在我的资源里有个spring融合DWR的小例子。。
我以前就是拿这个例子配置成功,希望对你有用。。
[其他解释]
引用:
在我的资源里有个spring融合DWR的小例子。。
我以前就是拿这个例子配置成功,希望对你有用。。

你这个是spring的么?
如果不是我就不下载了
[其他解释]
额。。。。我这里看不到我的资源。。我也记不太清楚了。。
我记得我以前的项目就是SSH+DWR做的额,那个资源里面说明了有Spring吗?
没有的话,那可能就不是的了。。
[其他解释]
引用:
额。。。。我这里看不到我的资源。。我也记不太清楚了。。
我记得我以前的项目就是SSH+DWR做的额,那个资源里面说明了有Spring吗?
没有的话,那可能就不是的了。。

你那个是struts的
不过我已经解决这个问题了
谢谢
[其他解释]
这个问题可以结贴了
因为这些个配置本身是没有问题的
只是因为不能够再spring已经注解service或者是controllor这样的类上进行注入了
或许可以
但是现在时间紧迫
我使用其他的类执行对应的java方法
如果需要注入一些bean或者services可以使用@Autowired进行注解
本次使用的是spring3.0 + dwr3.0进行整合的
谢谢各位的回复.散分了

读书人网 >J2EE开发

热点推荐