I'm using Mule 3.4. I kept a xml file in /src/main/resource/request and using initialize method and resource as stream, tried to load file from classpath and getting Null Pointer Exception
My configuration as follows spring.xml
<bean id="initSoapFault" class="org.hhmi.transformer.SOAPResponseTransformer" init-method="initialize" />
My Flow is following
<spring:beans>
<spring:import resource="classpath:conf/spring.xml"/>
</spring:beans>
My transformer class is code snippet is following
public void initialize() throws IOException {
try {
inputStream =Thread.currentThread().getContextClassLoader().getResourceAsStream("classpath:request/soapFault.xml");
docXmlResponse = IOUtils.toString(inputStream);
} finally {
IOUtils.closeQuietly(inputStream);
} }
The problem is most likely that you use the " classpath:
" prefix when invoking getResourceAsStream()
. That prefix should only be used in conjunction with a Spring ResourceLoader
, but not with a standard Java classloader
.
IT's working. I'm putting code snippet, it may help others
to get bean in transformer. I use following
private volatile ClassPathXmlApplicationContext context;
public SOAPResponseTransformer() {
context = new ClassPathXmlApplicationContext(getConfigResources());
}
protected String getConfigResources()
{
return "conf/spring.xml";
}
Then call where ever you need bean
ResourceInjection injection = (ResourceInjection) context.getBean("initSoapFault");
injection.getter Method
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.