spring-ws .wsdl doesnt contain ObjectFactory.class or jaxb.index - spring

I am following the spring guide to create the client of a web service. Firstly, I create the server and I don't have problems. I generated a jar and executed it. It returns the response.
These are my clases:
InventoryClient.java
public class InventoryClient extends WebServiceGatewaySupport {
public CatalogResponse getCatalog(Catalog cataog) {
Catalog request = new Catalog();
CatalogResponse response = (CatalogResponse) getWebServiceTemplate()
.marshalSendAndReceive("http://localhost:8080/ws/", request,
new SoapActionCallback(
"http://com.uciext.ws.hw5/Catalog"));
return response;
}
}
InventoryConfiguration.java
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
#Configuration
public class InventoryConfiguration {
#Bean
public Jaxb2Marshaller marshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
// this package must match the package in the <generatePackage> specified in
// pom.xml
marshaller.setContextPath("inventory.wsdl");
return marshaller;
}
#Bean
public InventoryClient getCatalog(Jaxb2Marshaller marshaller) {
InventoryClient client = new InventoryClient();
client.setDefaultUri("http://localhost:8080/ws");
client.setMarshaller(marshaller);
client.setUnmarshaller(marshaller);
return client;
}
}
Application.java
#SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
Util.log("---- Application: args[1] "+args[0]);
}
#Bean
void lookup(InventoryClient inventoryClient) {
Catalog catalog = new Catalog();
CatalogResponse response = inventoryClient.getCatalog(catalog);
Util.log("---- Application: date"+response.getReturn().getLastModifiedDate());
}
}
When I execute the jar, I get the following error
Unknown JAXB exception; nested exception is javax.xml.bind.JAXBException: Provider com.sun.xml.internal.bind.v2.ContextFactory could not be instantiated: javax.xml.bind.JAXBException: "inventory.wsdl" doesnt contain ObjectFactory.class or jaxb.index
- with linked exception:
[javax.xml.bind.JAXBException: "inventory.wsdl" doesnt contain ObjectFactory.class or jaxb.index]
When I created the server, I generated the classes from inventory.xsd

Try to make the wsdl package created by jaxb under JAVA Package directly

Related

Spring Boot/Batch with multiple #Configuration classes not instantiating bean (or loading properties)

So first, apologies if this seems to similar to other problems - I've looked, tried the proposed solutions, and none have solved the problems. First the sanitized code...
package com.mine.batchMain;
#SpringBootApplication
#Configuration
public class MyApplication implements CommandLineRunner {
//...
public static void main(String[] args) {
//....
}
}
package com.mine.batchMain;
//...
import com.min.batchMain.firstSteps.FirstStepConfigHolder;
//...
#Configuration
#EnableBatchProcessing
public class BatchConfigurer {
//....
#Autowired
private FirstStepConfigHolder firstStep;
//...
#Bean
public Step defineFirstStep() {
return stepBuilder.get("First Step")
.chunk<MyPOJO, MyPOJO>(batchSize)
.readerfirstStep.fetcher())
.writer(firstStep.extracter())
.listener(firstStep.listen())
.build();
}
//....
}
package com.mine.batchMain.firstSteps;
//...
import com.mine.batchMain.common.MyRepo;
import com.mine.batchMain.firstSteps.DocFetcher;
//...
#Configuration
#EnableJPARepositories
public class FirstStepConfigHolder {
//....
#Value("${myapp.dbUrl}")
String dbUrl;
#Value("${myapp.dbSchema}")
String dbSchema;
#Value("${myapp.dbUser}")
String dbUser;
#Value("${myapp.encDbPass}")
String encryptDbPass;
#Value("${myapp.dbDriver}")
String dbDriver;
#Value("${myapp.maxDocSize}")
String maxDocSize;
#Value("${myapp.maxNumDocs}")
String maxNumDocs;
#Bean
public DocFetcher fetcher() {
log.trace("Creating DocFetcher.")
return new DocFetcher(myDb());
}
#Bean
public MyRepo myDb() {
log.trace("Creating repo.");
MyRepo retDb = new MyRepo(myDataSource());
retDb.setMaxNumDocs(Integer.valueOf(maxNumDocs));
retDb.setMaxDocSize(Integer.valueOf(maxDocSize));
log.debug("Confirming db class state:"+retDb.toString());
return retDb;
}
private DataSource myDataSource() {
DriverManagerDataSource retDs = new DriverManagerDataSource(dbUrl, dbUser, decrypt(encryptDbPass));
retDs.setDriverClassName(dbDriver);
return retDs;
}
}
The problems/symptoms are these:
1) MyRepo is not picking up maxDocSize and maxNumDocs. (Logging shows the defaults)
2) Logging shows the trace call to "Creating DocFetcher", but not to "Creating repo.", nor is it showing the debug of the Repo state.
Which is frustrating, as according to what I know & understand, it should be picking them up. What am I missing and/or not understanding correctly?
Make sure that your BatchConfigurer.java file should be in the same package as your MainApplication.java file .
or,
Import BatchConfigurer.java in your MainApplication.java file.
Check this image for reference

Error creating bean with name 'scopedTarget.oauth2ClientContext': Scope 'request' is not active for the current thread for feign client

I am calling another microservice once my current microservice is up and ready using feign client in my current microservice built using Jhipster.
So my Feign Interface is
package com.persistent.integration.client;
import java.util.List;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.persistent.integration.service.dto.DataPipelineDTO;
#AuthorizedFeignClient(name = "Integrationconfiguration")
public interface DataPipelinesResourceFeign {
#RequestMapping(value = "/api/data-pipelines", method = RequestMethod.GET)
List<DataPipelineDTO> getAllDataPipelines(#RequestParam(value = "pageable") Pageable pageable );
}
}
And I have implemented ApplicationRunner where I have called feign client method.
#Component
public class ApplicationInitializer implements ApplicationRunner {
#Autowired
private DataPipelinesResourceFeign dataPipelinesResourceFeign;
#Autowired
private ActiveMQListener activeMqListener;
#Override
public void run(ApplicationArguments args) throws Exception {
// TODO Auto-generated method stub
Pageable pageable = PageRequest.of(0, 20);
try {
List <DataPipelineDTO> allStartedDataPipeLines = dataPipelinesResourceFeign.getAllDataPipelines(pageable); //.stream().filter(p->p.getState().equals(State.STARTED)).collect(Collectors.toList());
allStartedDataPipeLines.forEach(datapipe ->
{
try {
activeMqListener.consume(datapipe);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
});
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
But after running this, it gives below exception at dataPipelinesResourceFeign.getAllDataPipelines :
com.netflix.hystrix.exception.HystrixRuntimeException: DataPipelinesResourceFeign#getAllDataPipelines(Pageable) failed and no fallback available.
at com.netflix.hystrix.AbstractCommand$22.call(AbstractCommand.java:819)
at com.netflix.hystrix.AbstractCommand$22.call(AbstractCommand.java:804)
at rx.internal.operators.OperatorOnErrorResumeNextViaFunction$4.onError(OperatorOnErrorResumeNextViaFunction.java:140)
at rx.internal.operators.OnSubscribeDoOnEach$DoOnEachSubscriber.onError(OnSubscribeDoOnEach.java:87)
at rx.internal.operators.OnSubscribeDoOnEach$DoOnEachSubscriber.onError(OnSubscribeDoOnEach.java:87)
at com.netflix.hystrix.AbstractCommand$DeprecatedOnFallbackHookApplication$1.onError(AbstractCommand.java:1472)
Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'scopedTarget.oauth2ClientContext':
Scope 'request' is not active for the current thread; consider
defining a scoped proxy for this bean if you intend to refer to it
from a singleton; nested exception is java.lang.IllegalStateException:
No thread-bound request found: Are you referring to request attributes
outside of an actual web request, or processing a request outside of
the originally receiving thread? If you are actually operating within
a web request and still receive this message, your code is probably
running outside of DispatcherServlet/DispatcherPortlet: In this case,
use RequestContextListener or RequestContextFilter to expose the
current request. at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(Abstrac>tBeanFactory.java:362)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractB>eanFactory.java:199)
at
org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTarge>tSource.java:35)
at
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.>java:193)
at com.sun.proxy.$Proxy147.getAccessToken(Unknown Source) at
com.persistent.integration.security.oauth2.AuthorizationHeaderUtil.getAuthoriza>tionHeaderFromOAuth2Context(AuthorizationHeaderUtil.java:28)
at
com.persistent.integration.client.TokenRelayRequestInterceptor.apply(TokenRelay>RequestInterceptor.java:23)
at
feign.SynchronousMethodHandler.targetRequest(SynchronousMethodHandler.java:158)
at
feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:88)
at
feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:76)
at
feign.hystrix.HystrixInvocationHandler$1.run(HystrixInvocationHandler.java:108)
at com.netflix.hystrix.HystrixCommand$2.call(HystrixCommand.java:302)
at com.netflix.hystrix.HystrixCommand$2.call(HystrixCommand.java:298)
at
rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:46)
... 68 more Caused by: java.lang.IllegalStateException: No
thread-bound request found: Are you referring to request attributes
outside of an actual web request, or processing a request outside of
the originally receiving thread? If you are actually operating within
a web request and still receive this message, your code is probably
running outside of DispatcherServlet/DispatcherPortlet: In this case,
use RequestContextListener or RequestContextFilter to expose the
current request. at
org.springframework.web.context.request.RequestContextHolder.currentRequestAttr>ibutes(RequestContextHolder.java:131)
at
org.springframework.web.context.request.AbstractRequestAttributesScope.get(Abst>ractRequestAttributesScope.java:42)
at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(Abstrac>tBeanFactory.java:350)
many suggestions on internet were to add listerner RequestContextListener. But problem persisted even if I added listener in webConfigurer.java in onStartup method.
{
servletContext.addListener(RequestContextListener.class);
}
But of no use.
Any leads would be appreciated.
I found a workaround for this. I don't know why TokenRelayRequestIntercepton isn't working but you can use your own RequestInterceptor based on Spring's SecurityContext.
First, define a RequestInterceptor :
public class MyRequestInterceptor implements RequestInterceptor {
public static final String AUTHORIZATION = "Authorization";
public static final String BEARER = "Bearer";
public MyRequestInterceptor() {
super();
}
#Override
public void apply(RequestTemplate template) {
// demander un token à keycloak et le joindre à la request
Optional<String> header = getAuthorizationHeader();
if (header.isPresent()) {
template.header(AUTHORIZATION, header.get());
}
}
public static Optional<String> getAuthorizationHeader() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication != null && authentication.getDetails() != null && authentication.getDetails() instanceof OAuth2AuthenticationDetails) {
OAuth2AuthenticationDetails oAuth2AuthenticationDetails =
(OAuth2AuthenticationDetails) authentication.getDetails();
return Optional.of(String.format("%s %s", oAuth2AuthenticationDetails.getTokenType(),
oAuth2AuthenticationDetails.getTokenValue()));
} else {
return Optional.empty();
}
}
}
and then, declare a config class for your feign client using your RequestInterceptor, it should contains something like this :
#Bean(name = "myRequestInterceptor")
public RequestInterceptor getMyRequestInterceptor() throws IOException {
return new MyRequestInterceptor();
}
Your Feign client shoud look like this:
#FeignClient(name = "SERVICE_NAME", configuration = MyFeignConfiguration.class)
public interface MyRestClient {
I had the same issue with Feign Client running on startup using ApplicationRunner and I came up with following solution.
I defined my FeignClientsConfiguration with OAuth2FeignRequestInterceptor, which accepts predefined bean DefaultOAuth2ClientContext and OAuth2 configuration OAuth2ProtectedResourceDetails:
#Configuration
public class MyConfig extends FeignClientsConfiguration {
#Bean
public RequestInterceptor oauth2FeignRequestInterceptor( DefaultOAuth2ClientContext oAuth2ClientContext, MyOauth2Properties properties) {
return new OAuth2FeignRequestInterceptor(oAuth2ClientContext, resourceDetails(properties));
}
#Bean
public DefaultOAuth2ClientContext oAuth2ClientContext() {
return new DefaultOAuth2ClientContext();
}
private OAuth2ProtectedResourceDetails resourceDetails(MyOauth2Properties oauth2Properties) {
ResourceOwnerPasswordResourceDetails resourceDetails = new ResourceOwnerPasswordResourceDetails();
resourceDetails.setAccessTokenUri(oauth2Properties.getAccessTokenUri());
resourceDetails.setUsername(oauth2Properties.getUsername());
resourceDetails.setPassword(oauth2Properties.getPassword());
resourceDetails.setClientId(oauth2Properties.getClientId());
return resourceDetails;
}
}
Your feign client will look something like this:
#FeignClient(url = "http://localhost:8080/api/v1")
public interface FeignClient {
}
After all this, calling FeignClient from ApplicationRunner.run() works fine.
Spring Boot 2.2.6

Configuring JNDI URL resources in embedded Tomcat Spring Boot application

I am having a Spring Boot application with embedded Tomcat server. My application does JNDI look up of datasource and config file URL.
I am able to configure JNDI datasource but i am unable to configure JNDI URL in embedded Tomcat. Same application when deployed as WAR to standalone Liberty server is working fine as Liberty is configured properly with JNDI datasource and config file URL.
Also JNDI data sources and URLs are defined in spring config file in a jar of my application which is common and I cannot modify it but only import.
This is how i am trying to configure embedded tomcat
import java.net.URL;
import javax.sql.DataSource;
import org.apache.catalina.Context;
import org.apache.catalina.startup.Tomcat;
import org.apache.tomcat.util.descriptor.web.ContextResource;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ImportResource;
import org.springframework.context.annotation.Profile;
#SpringBootApplication(exclude = { JmxAutoConfiguration.class,DataSourceAutoConfiguration.class })
#ImportResource(locations = { "classpath:common-services.xml" })
public class MyApplication extends SpringBootServletInitializer {
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(MyApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
#Bean
#Profile("dev")
public TomcatEmbeddedServletContainerFactory tomcatFactory() {
return new TomcatEmbeddedServletContainerFactory() {
#Override
protected TomcatEmbeddedServletContainer getTomcatEmbeddedServletContainer(Tomcat tomcat) {
tomcat.enableNaming();
return super.getTomcatEmbeddedServletContainer(tomcat);
}
#Override
protected void postProcessContext(Context context) {
ContextResource resource = new ContextResource();
resource.setName("jdbc/myDataSource");
resource.setType(DataSource.class.getName());
resource.setProperty("driverClassName", "oracle.jdbc.OracleDriver");
resource.setProperty("url", "jdbc:oracle:thin:#sadasd");
resource.setProperty("username", "admin");
resource.setProperty("password", "admin");
resource.setProperty("factory", "org.apache.tomcat.jdbc.pool.DataSourceFactory");
context.getNamingResources().addResource(resource);
ContextResource queryOnlyDataSourceResource = new ContextResource();
queryOnlyDataSourceResource.setName("jdbc/queryOnlyDataSource");
queryOnlyDataSourceResource.setType(DataSource.class.getName());
queryOnlyDataSourceResource.setProperty("driverClassName", "oracle.jdbc.OracleDriver");
queryOnlyDataSourceResource.setProperty("url", "jdbc:oracle:thin:#osajodoajo");
queryOnlyDataSourceResource.setProperty("username", "admin");
queryOnlyDataSourceResource.setProperty("password", "admin");
queryOnlyDataSourceResource.setProperty("factory", "org.apache.tomcat.jdbc.pool.DataSourceFactory");
context.getNamingResources().addResource(queryOnlyDataSourceResource);
ContextResource dataSourceOrbisExport = new ContextResource();
dataSourceOrbisExport.setName("jdbc/exportDataSource");
dataSourceOrbisExport.setType(DataSource.class.getName());
dataSourceOrbisExport.setProperty("driverClassName", "oracle.jdbc.OracleDriver");
dataSourceOrbisExport.setProperty("url", "jdbc:oracle:thin:#saddalsdkla");
dataSourceOrbisExport.setProperty("username", "admin");
dataSourceOrbisExport.setProperty("password", "admin");
dataSourceOrbisExport.setProperty("factory", "org.apache.tomcat.jdbc.pool.DataSourceFactory");
context.getNamingResources().addResource(dataSourceOrbisExport);
// File Configuration
ContextResource engineConfigResource = new ContextResource();
evolutionEngineConfigResource.setName("url/engineConfig");
evolutionEngineConfigResource.setType(URL.class.getName()); resource.setProperty("protocol","file");
evolutionEngineConfigResource.setProperty("file", "C:/configuration_DIT/EngineConfig.config");
context.getNamingResources().addResource(engineConfigResource);
ContextResource evolutionPresentationConfigResource = new ContextResource();
presentationConfigResource.setName("url/presentationConfig");
presentationConfigResource.setType(URL.class.getName()); resource.setProperty("protocol","file");
evolutionPresentationConfigResource.setProperty("file", "C:/configuration_DIT/presentation.config");
context.getNamingResources().addResource(presentationConfigResource);
}
};
}
}
This is what error says :
required a bean of type 'java.net.URL' that could not be found.
Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'engineConfig': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name [url/engineConfig] is not bound in this Context. Unable to find [url].

#Value not working even if key is resolved [Spring 4]

My constants.java is like this:
package com.sample.utils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
#Component(value="ConstantValues")
public class Constants {
static {
System.out.println("Class loaded: Constants");
}
#Value("${allowxmlvalue}")
private String logXMLString;
public String getLogXMLString() {
return logXMLString;
}
public void setLogXMLString(String logXMLString) {
this.logXMLString = logXMLString;
}
}
I am loading Application using spring boot like this:
#Configuration
#PropertySources({
#PropertySource("file:/home/ubuntu/config/properties/app.properties"),
#PropertySource("file:/home/ubuntu/config/properties/util.properties")})
#ComponentScan(basePackages = {
"com.sample.utils"
})
#EnableAutoConfiguration
public class Sample {
static Logger logger = Logger.getLogger(Sample.class);
public static void main(String[] args) throws Exception {
SpringApplication.run(Sample.class, args);
Constants cons = new Constants();
logger.info("Print XML: "+cons.getLogXMLString());
}
}
I can see following print in logs:
20:40:45,865 DEBUG PropertySourcesPropertyResolver:90 - Found key
'allowxmlvalue' in [URL
[/home/ubuntu/config/properties/app.properties]] with type [String]
and value 'print xml value'
But still Print XML: null is printed out, What I may be missing here?
You're creating the Constants instance yourself instead of getting the Spring managed bean. Obviously its fields won't have been processed by Spring.
So get it from Spring
ApplicationContext ctx = SpringApplication.run(Sample.class, args);
Constants cons = ctx.getBean(Constants.class);
or inject it into the Sample bean.

#Autowired does not work with my SOAP handler class. Throws a nullPointerException?

This is my SOAP Handler class to generate security service handlers for a CRM. Everything was working fine as I hard coded my credentials - Username & Password. Now I tried to remove the hard-coding by defining the credentials in a properties file and autowiring it in this class. This method is not working and Spring throws a NullPointerExc (autowiring not happening I guess!) everytime I try to access my CRM. Why does #Autowired not work here while it works perfectly well my #Service, #Controller classes? Here is my code:
package com.myPortlet.crmService;
import java.util.Properties;
import javax.xml.namespace.QName;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPFactory;
import javax.xml.soap.SOAPHeader;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.soap.SOAPHandler;
import javax.xml.ws.handler.soap.SOAPMessageContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
#Component
public class ECMClientHeaderHandler implements SOAPHandler<SOAPMessageContext> {
final static Logger logger = LoggerFactory
.getLogger(ECMClientHeaderHandler.class);
private static final String AUTH_NS = "http://schemas.xmlsoap.org/ws/2002/12/secext";
private static final String AUTH_PREFIX = "wss";
public ECMClientHeaderHandler() {
}
public boolean handleFault(SOAPMessageContext smc) {
return true;
}
public void close(MessageContext mc) {
}
#Autowired
private Properties applicationProperties;
public boolean handleMessage(SOAPMessageContext smc) {
boolean direction = ((Boolean) smc
.get(SOAPMessageContext.MESSAGE_OUTBOUND_PROPERTY))
.booleanValue();
String userName = applicationProperties.getProperty("myCRM.userName"); /*previously hard-coded*/
String password = applicationProperties.getProperty("myCRM.password"); /*previously hard-coded*/
logger.info("This is USERNAME:"+ userName);
logger.info("This is PASSWORD:"+ password);
if (direction) {
try {
SOAPEnvelope envelope = smc.getMessage().getSOAPPart()
.getEnvelope();
SOAPFactory soapFactory = SOAPFactory.newInstance();
// WSSecurity <Security> header
SOAPElement wsSecHeaderElm = soapFactory.createElement(
"Security", AUTH_PREFIX, AUTH_NS);
SOAPElement userNameTokenElm = soapFactory.createElement(
"UsernameToken", AUTH_PREFIX, AUTH_NS);
SOAPElement userNameElm = soapFactory.createElement("Username",
AUTH_PREFIX, AUTH_NS);
userNameElm.addTextNode(userName);
SOAPElement passwdElm = soapFactory.createElement("Password",
AUTH_PREFIX, AUTH_NS);
passwdElm.addTextNode(password);
userNameTokenElm.addChildElement(userNameElm);
userNameTokenElm.addChildElement(passwdElm);
// add child elements to the root element
wsSecHeaderElm.addChildElement(userNameTokenElm);
// create SOAPHeader instance for SOAP envelope
SOAPHeader sh;
if(envelope.getHeader()==null){
logger.info("SOAPHeader null.Add header");
sh = envelope.addHeader();
}else{
logger.info("SOAPHeader already present");
sh = envelope.getHeader();
}
// add SOAP element for header to SOAP header object
sh.addChildElement(wsSecHeaderElm);
} catch (Exception ex) {
ex.printStackTrace();
throw new RuntimeException(ex);
}
}
return true;
}
public java.util.Set<QName> getHeaders() {
return null;
}
}
The "myCRM.userName" & "myCRM.password" is defined in my application.properties file. And the classPath of application.properties is defined in applicationContext.xml:
<util:properties id="applicationProperties" location="classpath:/i18n/application.properties"/>
What is going wrong?
The Spring Context has to be made aware that it needs to load some autowired components on a specific class. The #Controller annotation and a reference in the spring-servlet.xml ensure just that.
You can try adding this to your spring-servlet.xml
<context:component-scan base-package="com.myPortlet.crmService" />
Also Add a #Controller annotation in your class to initiate auto wiring at server startup. Else your Properties instance will be null everytime you try to access it.
I had a similar problem trying injecting a dependency in my #webservice class. I solved it adding the method below in the class (org.springframework.web.context.support.SpringBeanAutowiringSupport;)
#PostConstruct
#WebMethod(exclude = true)
public void init() {
SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
}

Resources