读书人

有关SPRING+CXF的有关问题。跪求。

发布时间: 2013-06-25 23:45:42 作者: rapoo

有关SPRING+CXF的问题。。跪求。。
刚开始研究CXF有好多疑问。。希望前辈们指教
已经将WSDL文件发布成功
在本机上可以访问 http://localhost:8080/permiss/services/UserService?wsdl 得到XML文件
我在自己机器上测试方法
public static void main(String[] args) { /
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(UserInfoService.class);
factory.setAddress ("http://localhost:8080/permiss/services/UserService?wsdl");
UserInfoService service = (UserInfoService) factory.create();
String user = service.getUserInfo();
System.out.println(user);

方法如下:
@Service
@WebService(endpointInterface = "com.seven.webService.UserInfoService")
@SOAPBinding(style = Style.RPC)
public class UserInfoServiceImpl extends BaseService<User> implements UserInfoService {

private User user;
private UserDao userDao;
@Autowired
public void setUserDao(UserDao userDao) {
this.userDao = userDao;
super.setDao(userDao);
}

public String getUserInfo() {
// TODO Auto-generated method stubf
return "success";
}
如果这样调用的话会调用成功的都返回的SUCCESS

但是如果我在方法中添加一条访问数据库的语句就报错啦。。
public String getUserInfo() {
// TODO Auto-generated method stubf
userDao.findAll();
return "success";
}
我一共做了下面几个步骤
1.添加JAR包
2.在userService中添加下面注解
@Service
@WebService(endpointInterface = "com.seven.webService.UserInfoService")
@SOAPBinding(style = Style.RPC)
3.web.xml加入CXF的配置文件
4.APPLICATIONcontext.xml中的代码如下。。
<!-- 配置spring提供的属性文件加载器 -->
<context:property-placeholder location="classpath:jdbc.properties"/>

<!-- 启用基于注解方式的IoC配置 -->
<context:component-scan base-package="com.seven"/>

<!-- 带c3p0连接池的数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="${jdbc.driver}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="user" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>

<!-- 其它的一些优化参数 -->
<property name="minPoolSize" value="5"/>
<property name="maxPoolSize" value="30"/>
<property name="checkoutTimeout" value="1800"/>
<property name="maxStatements" value="20"/>
</bean>

<!-- ==============================DAO层 -->
<!-- Spring为Hibernate提供的一个SessionFactory实体类,它产生的Session会自动绑定到当前线程上-->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml"/>


<property name="dataSource" ref="dataSource"/>
</bean>



<!-- ==============================Service层 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- =======声明式事务的配置-->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*" isolation="READ_COMMITTED" />
<tx:method name="get*" isolation="READ_COMMITTED" read-only="true"/>
<tx:method name="load*" isolation="READ_COMMITTED" read-only="true"/>
<tx:method name="find*" isolation="READ_COMMITTED" read-only="true"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:advisor advice-ref="txAdvice" pointcut="execution(* com.seven.service..*.*(..))"/>
</aop:config>

<!--<jaxws:endpoint id="greetingService"
implementor="com.gary.test.ws.service.impl.GreetingServiceImpl"
address="/GreetingService" />
-->
<jaxws:endpoint id="userWebService"
implementor="com.seven.webService.impl.UserInfoServiceImpl"
address="/UserService" />
</beans>

5.还有就是APPLICATION。xml中我看别人都有这几条语句 我一加上就报错。。找不到路径
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml" />

6.问题就描述这么多了 。。有什么地方不清楚请回帖问我。。在线等。。谢谢前辈们指教。。
Spring cxf
[解决办法]
你的dao没有注入进去,你用在数据库操作的地方加个断点看看是不是报的空指针异常?
[解决办法]
把你报的错发出来,不然没法定位问题。
[解决办法]

引用:
Quote: 引用:

你的userDao现在是空的吗
哎呀 还真是空的 - -咋整啊~~
UserInfoServiceImpl这个类里面没有注入UserDao ,而且你用@AutoWire的话,写法有点怪。

读书人网 >J2EE开发

热点推荐