我有一行代码:File file = new File(getFile())在java类中HandleData.java
方法 - getFile()获取属性的值fileName.并fileName通过application_context.xml类的bean部分注入 - HandleData如下:
<bean id="dataHandler" class="com.profile.transaction.HandleData">
<property name="fileName" value="DataFile.xml"></property>
</bean>
Run Code Online (Sandbox Code Playgroud)
我成功地构建了项目并检查了 - DataFile.xml是否存在WEB-INF/classes.并且HandleData.class存在于WEB-INF/classes/com/profile/transacon
但是当我运行它时会抛出filenotfound异常.如果我注入绝对路径(C:\MyProjectWorkspace\DataProject\target\ProfileService\WEB-INF\classes\DataFile.xml它成功找到文件).
有人可以帮助确定要注入的正确路径,以便从类路径中获取文件吗?
嗨,我已经启动并运行了web服务,我使用了jax ws.我已经使用Spring来使用带有Autowired的bean和spring给出的类似于applicationContext.xml中的属性值注入的东西.
我有以下spring applicationcontext.xml条目:
<context:component-scan base-package="com.mybeans.service" />
<bean id="myProperty" class="com.mybeans.service.MyBeanProperty"
p:Size="BIG">
</bean>
Run Code Online (Sandbox Code Playgroud)
在Web服务端点类中,我做了:
@Autowired private MyBeanProperty myProperty;
Run Code Online (Sandbox Code Playgroud)
我有一个方法:
public String getSize() {
return myProperty.getSize();
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,当我调用该方法时,它没有获得任何值并抛出nullpointerexception.
PS:我使用soapUI来运行webservice的wsdl并调用该方法.
Web服务是否在Spring创建bean之前运行?
为了duffmo
是的我在applicationContext中使用了组件扫描.我确实有web.xml中的上下文加载器监听器.请帮我..
这是我完整的代码解释代码
我正在使用JAX-WS和Spring并尝试设置一些需要在Tomcat 7上运行的Web服务.我使用Maven作为构建工具,因此我只列出了我的两个依赖项:
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
<dependencies>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.1.3</version>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
我的服务类位于com.test.services中,名为TestService&HelloWorldService,如下所示:
package com.test.services;
import javax.jws.WebMethod;
import javax.jws.WebService;
@WebService( name = "Test", serviceName = "TestService" )
public class TestService {
@WebMethod
public String getTest() {
return "Test";
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" …Run Code Online (Sandbox Code Playgroud)