spring controller referring to service using configuration file - spring

I have a spring mvc project. I have a controller defined as follows:
public class HelloController {
private HelloService helloService;
#RequestMapping("/hello")
public void sayHello() {
helloService.sayHello();
}
}
My service is as follows:
public class HelloServiceImpl implements HelloService {
public void sayHello() {
System.out.println("Hello Spring !");
}
}
The interface is as follows:
public interface HelloService {
void sayHello();
}
and my configuration file is as follows:
<mvc:annotation-driven/>
<context:component-scan base-package="com.pack"/>
<bean id="HelloController" class="com.pack.controllers.HelloController">
<property name="helloService" ref="HelloService"></property>
</bean>
<bean id="HelloService" class="com.pack.services.HelloServiceImpl"/>
I can use annotations on the controller and the service and autowire the service using annotation #autowired which works fine.
I was trying to achieve the same using configuration file. Is there a way to do it ?
I am getting the following exception while running it:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'HelloController' defined in ServletContext resource [/WEB-INF/config/servlet-config.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'helloService' of bean class [adams.invincible.controllers.HelloController]: Bean property 'helloService' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1423)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1128)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:628)
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:651)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:599)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:665)
org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:518)
org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:459)
org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
javax.servlet.GenericServlet.init(GenericServlet.java:158)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Thread.java:745)
root cause
org.springframework.beans.NotWritablePropertyException: Invalid property 'helloService' of bean class [adams.invincible.controllers.HelloController]: Bean property 'helloService' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1042)
org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:902)
org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:75)
org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:57)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1420)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1128)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:628)
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:651)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:599)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:665)
org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:518)
org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:459)
org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
javax.servlet.GenericServlet.init(GenericServlet.java:158)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Thread.java:745)

You can achieve it by providing setter method for injecting helloService as shown below
//setter injection
public void setHelloService(HelloService helloService) {
this.helloService = helloService;
}
Or You can achieve it by providing constructor for injecting helloService using constructor injection as shown below
//Constructor injection
public HelloController (HelloService helloService) {
this.helloService = helloService;
}
// changes in configuration file
<bean id="HelloController" class="com.pack.controllers.HelloController">
<constructor-arg ref="HelloService"/>

Adding the setter and getter for helloservice in HelloController class will take care of it. There should NOT be a need to add #autowired annotation after doing that

The error is saying that you need generate the get and set for the bean helloService.
Bean property 'helloService' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter
But if you trying inject the bean, even making the configuration manually , you need to put the annotation #Autowire
#Autowire
private HelloService helloService;

Related

Unable to receive spring activemq message

I am trying to configure JMS in Spring with activeMQ, here is my sender code
#Service
public class SenderService implements ISenderService{
#Bean
public ActiveMQConnectionFactory amqConnectionFactory() {
return new ActiveMQConnectionFactory(BROKER_URL);
}
#Bean
public Destination defaultDestination( ) {
return new ActiveMQQueue(MAILBOX_QUEUE);
}
#Bean
public JmsTemplate jmsTemplate( ) {
JmsTemplate jmsTemplate = new JmsTemplate();
jmsTemplate.setDefaultDestination(defaultDestination());
jmsTemplate.setConnectionFactory(amqConnectionFactory());
return jmsTemplate;
}
public void send(final EmailMessage emailMessage) {
jmsTemplate().send(new MessageCreator() {
public Message createMessage(Session session) throws JMSException {
return session.createObjectMessage(emailMessage);
}
});
}
}
When I check http://localhost:8161/admin/queues.jsp, I can see a message is incremented in the list, however I am unable to receive this message.
#Component
public class MessageConsumer implements MessageListener {
#JmsListener(destination = ISenderService.MAILBOX_QUEUE)
public void onMessage(Message arg0) {
System.out.println("MMMMMMMMMMMMMMMMMMMMMMMMMMMM");
}
}
If I create above class and try to deploy war on tomcat7 I see following error.
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'jmsListenerContainerFactory' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:687) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1168) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:281) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.jms.config.JmsListenerEndpointRegistrar.resolveContainerFactory(JmsListenerEndpointRegistrar.java:139) ~[spring-jms-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.jms.config.JmsListenerEndpointRegistrar.registerAllEndpoints(JmsListenerEndpointRegistrar.java:126) ~[spring-jms-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.jms.config.JmsListenerEndpointRegistrar.afterPropertiesSet(JmsListenerEndpointRegistrar.java:121) ~[spring-jms-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.jms.annotation.JmsListenerAnnotationBeanPostProcessor.afterSingletonsInstantiated(JmsListenerAnnotationBeanPostProcessor.java:185) ~[spring-jms-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:775) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403) [spring-web-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) [spring-web-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) [spring-web-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5001) [catalina.jar:7.0.64]
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5517) [catalina.jar:7.0.64]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [catalina.jar:7.0.64]
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901) [catalina.jar:7.0.64]
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877) [catalina.jar:7.0.64]
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652) [catalina.jar:7.0.64]
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1095) [catalina.jar:7.0.64]
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1930) [catalina.jar:7.0.64]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_60]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_60]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_60]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_60]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_60]
See the documentation.
You have to provide a listener container factory so the framework knows how to wire up each listener container - connection factory etc.
If your app is a Spring Boot app spring boot will wire one up for you automatically.

Creating a spring bean with Configuration annotation

guys, I want to register and inject a spring bean with the Configuration annotation but without success. Here is the bean I want to create on a abstract level:
public class MyBean{
private AnotherBean anotherBean;
private String someString;
public MyBean(AnotherBean anotherBean, String someString) {
this.anotherBean= anotherBean;
this.someString= someString;
}
public MyBean(){}
public MyPojo someMethod(MyPojo oject, final String anyString) {
//some logic
}
}
Here is my Configuration class:
#Configuration
public class BeanConfiguration {
private static final String SOME_STRING = "someString";
#Inject
#Qualifier("anotherBean")
private AnotherBean otherBean;
#Bean(name = "myBean")
public MyBean getMyBean(){
MyBean myBean= new MyBean(otherBean, SOME_STRING );
return myBean;
}
}
And I declare in the application context the configuration bean:
<bean class="configuration.package.BeanConfiguration"/>
So the the problem is that the spring container creates an BeanConfiguration object but the getMyBean() method is never hit, so my bean is never registered and when I try to inject it an exception telling me that the bean can not be autowired, so it is not injected(and that is normal, because the bean is not registered). Here is the stack trace
10:33:03.322 [http-apr-8080-exec-8] ERROR o.s.web.servlet.DispatcherServlet - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bet': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private my.bean.package.MyBean
my.bean.package.MyBean; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [my.bean.package.MyBean] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {#javax.inject.Inject()}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:288) ~[AutowiredAnnotationBeanPostProcessor.class:3.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1122) ~[AbstractAutowireCapableBeanFactory.class:3.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522) ~[AbstractAutowireCapableBeanFactory.class:3.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461) ~[AbstractAutowireCapableBeanFactory.class:3.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295) ~[AbstractBeanFactory$1.class:3.2.2.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) ~[DefaultSingletonBeanRegistry.class:3.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292) ~[AbstractBeanFactory.class:3.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[AbstractBeanFactory.class:3.2.2.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626) ~[DefaultListableBeanFactory.class:3.2.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) ~[AbstractApplicationContext.class:3.2.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) ~[AbstractApplicationContext.class:3.2.2.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:651) ~[FrameworkServlet.class:3.2.2.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:599) ~[FrameworkServlet.class:3.2.2.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:665) ~[FrameworkServlet.class:3.2.2.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:518) ~[FrameworkServlet.class:3.2.2.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:459) ~[FrameworkServlet.class:3.2.2.RELEASE]
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136) [HttpServletBean.class:3.2.2.RELEASE]
at javax.servlet.GenericServlet.init(GenericServlet.java:158) [servlet-api.jar:3.1.FR]
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1241) [catalina.jar:8.0.9]
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1154) [catalina.jar:8.0.9]
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:827) [catalina.jar:8.0.9]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:135) [catalina.jar:8.0.9]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) [catalina.jar:8.0.9]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503) [catalina.jar:8.0.9]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136) [catalina.jar:8.0.9]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [catalina.jar:8.0.9]
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610) [catalina.jar:8.0.9]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) [catalina.jar:8.0.9]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526) [catalina.jar:8.0.9]
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078) [tomcat-coyote.jar:8.0.9]
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:655) [tomcat-coyote.jar:8.0.9]
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:277) [tomcat-coyote.jar:8.0.9]
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2381) [tomcat-coyote.jar:8.0.9]
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2370) [tomcat-coyote.jar:8.0.9]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_60-ea]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_60-ea]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-util.jar:8.0.9]
at java.lang.Thread.run(Thread.java:745) [na:1.7.0_60-ea]
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private my.bean.package.MyBean my.bean.package.myBean; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [my.bean.package.MyBean] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {#javax.inject.Inject()}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:514) ~[AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.class:3.2.2.RELEASE]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87) ~[InjectionMetadata.class:3.2.2.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285) ~[AutowiredAnnotationBeanPostProcessor.class:3.2.2.RELEASE]
... 37 common frames omitted
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [my.bean.package.MyBean] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {#javax.inject.Inject()}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:986) ~[DefaultListableBeanFactory.class:3.2.2.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:856) ~[DefaultListableBeanFactory.class:3.2.2.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:768) ~[DefaultListableBeanFactory.class:3.2.2.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:486) ~[AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.class:3.2.2.RELEASE]
... 39 common frames omitted
So I can't see why my bean is not registered, so if anyone can help I would be grateful.
The first problem is because you use private with inject and you dont have the set function, and the other problem is because you dont have the <bean class="....MyBean"/> in your xml configuration

Session Objects when using Spring Webflow

I have few variables which need to be stored in the session as they should be available until the page closes.
I came up with session object, that can store the values, so that i can refer them to any class by injecting whenever necessary.
#Component
#Scope("session")
public class SessionObjects {
/**
* Boradcaster id of the atmosphere
*/
private String broadCasterId;
/**
* Atmosphere Resource Id of specific session
*/
private String senderId;
public String getBroadCasterId() {
return broadCasterId;
}
public void setBroadCasterId(String broadCasterId) {
this.broadCasterId = broadCasterId;
}
public String getSenderId() {
return senderId;
}
public void setSenderId(String senderId) {
this.senderId = senderId;
}
}
But when i start the application server, it fails with this error.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'wb': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.emyed.whiteboard.controller.SessionObjects com.emyed.whiteboard.defaults.wb.baseMB; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:288) ~[spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1116) ~[spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) ~[spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) ~[spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295) ~[spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) ~[spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292) ~[spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626) ~[spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) ~[spring-context-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) ~[spring-context-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389) ~[spring-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294) ~[spring-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112) [spring-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939) [catalina.jar:7.0.42]
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434) [catalina.jar:7.0.42]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [catalina.jar:7.0.42]
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901) [catalina.jar:7.0.42]
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877) [catalina.jar:7.0.42]
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633) [catalina.jar:7.0.42]
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:976) [catalina.jar:7.0.42]
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1653) [catalina.jar:7.0.42]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) [na:1.6.0_25]
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) [na:1.6.0_25]
at java.util.concurrent.FutureTask.run(FutureTask.java:138) [na:1.6.0_25]
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [na:1.6.0_25]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [na:1.6.0_25]
at java.lang.Thread.run(Thread.java:662) [na:1.6.0_25]
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.emyed.whiteboard.controller.SessionObjects com.emyed.whiteboard.defaults.wb.baseMB; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:514) ~[spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87) ~[spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285) ~[spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
... 27 common frames omitted
Caused by: java.lang.NullPointerException: null
at org.springframework.web.context.request.SessionScope.get(SessionScope.java:91) ~[spring-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:329) ~[spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
Sample wb class
#Named
public class Wb implements Serializable{
#Autowired
private SessionObjects sessionObj;
/**
* Creates a new whiteboard
*
* #return string outcome for navigation
*/
public WhiteboardIdentifiers create() {
String senderId = UUID.randomUUID().toString();
String whiteboardID = UUID.randomUUID().toString();
UserData creator = new UserData(senderId, getCreator(),null);
return createWhiteboard.create( senderId, whiteboardID, creator);
}
public DisplayWhiteboard setDisplayWhiteboard(WhiteboardIdentifiers wbIdentifiers){
........
// set the id's in the baseMB
sessionObj.setBroadCasterId(whiteboardId);
//Chat Controller
......
sessionObj.setSenderId(senderId);
whiteboard.getUserController().activateUser(senderId);
}
}

Spring error when parameter added to bean configuration

I am using Spring and Spring Annotations to configure service layer:
Below code works fine:
#Configuration
public class AccountServices {
#Bean
public List<String> getSourceAccountsList() { //Do something }
But as soon as I change the Bean configuration method to take the string parameter (below code), I get error.
#Configuration
public class AccountServices {
#Bean
public List<String> getSourceAccountsList(String userId) { //Do something }
The error is:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'getSourceAccountsList' defined in class path resource [net/iranet/isc/saba/services/AccountServices.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [java.lang.String]: : No qualifying bean of type [java.lang.String] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [java.lang.String] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:730)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:461)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1025)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:921)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:487)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:628)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [java.lang.String] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:988)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:858)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:770)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:795)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:723)
... 30 more
I think you are using #Bean in a wrong way, especially in #Service layer (and usually #Bean method doesn't have a get, but only , in your case sourceAccountsList()). Who provide the userId parameter, the web controller?
If AccountService is called from a controller you have something like (pseudo-code):
#Service
public class AccountServices {
public List<String> getAccountService(String userId) {
// Retrieve List<String> from database, or file, or somewhere else via DAO
// directly
}
}
#Controller
public class Controller {
#Autowired
private AccountsService accountService;
public void doAction(Request request) {
String userId = request.getParameter("userId");
request.putParameter("accountsList",this.accountService.getSourceAccountsList(userId));
forwardTo("/newPage.jsp", request);
}
}
Read about controller/service/repository in Spring means (Google search with a lot of resource) and from SpringSource.
After you understand layer separation you can add #Transaction management (for example) and all other feature you need.
When you use #Configuration and #Bean annotations you configure beans, parameters for methods annotated with #Bean are threated as references to another beans, so you should add bean with class String and probably name of bean "userId" - name of parameter used for autowire by name.

Spring 3.2 bean with constructor fails to initialize because of an injected property using #Required

In a Spring 3.2 project, I am bootstraping a service bean which has an injected property. The property is injected using #Required #Value(...) from a property file. I am sure the property file is being recognozed well by the spring context though.
Please check the service class below:
#Service
public class SomeService {
private String aURIString;
#Required
#Value("${someUrl}")
public void setaURIString(String aURIString) {
this.aURIString = aURIString;
}
private URI oamURI;
public SomeService() throws Exception {
super();
try {
oamURI = new URI(aURIString);
} catch (URISyntaxException e) {
throw new Exception("URISyntaxException created while creating a URI instance for url= "+aURIString);
}
}
}
Also please find the Configuration Class below
#Configuration
#EnableWebMvc
#PropertySource({ "classpath:filter.properties" })
#ComponentScan(basePackages = { "com.someOrg.SomePrj" })
public class WebConfig extends WebMvcConfigurerAdapter {
#Bean
public static PropertySourcesPlaceholderConfigurer properties() {
return new PropertySourcesPlaceholderConfigurer();
}
#Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}
}
As well as the property file "filter.properties"
someUrl=http://www.google.com
When I test using the following test file
#RunWith(SpringJUnit4ClassRunner.class)
#WebAppConfiguration
#ContextConfiguration(classes = {WebConfig.class})
public class RestTemplateTest {
#Resource
private SomeService someService;
#Test
public void testService() {
}
}
I get the following exception
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:99)
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:122)
at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:105)
at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:74)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:312)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:288)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:284)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'someService' defined in file [C:\CVS_Checkouts\someSpace\SomePrj\target\classes\com\someOrg\SomePrj\SomeService\SomeService.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.someOrg.SomePrj.SomeService.SomeService]: Constructor threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1013)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:959)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:490)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.test.context.web.AbstractGenericWebContextLoader.loadContext(AbstractGenericWebContextLoader.java:128)
at org.springframework.test.context.web.AbstractGenericWebContextLoader.loadContext(AbstractGenericWebContextLoader.java:60)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:100)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:248)
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContextInternal(CacheAwareContextLoaderDelegate.java:64)
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:91)
... 25 more
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.someOrg.SomePrj.SomeService.SomeService]: Constructor threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1006)
... 41 more
Caused by: java.lang.NullPointerException
at java.net.URI$Parser.parse(Unknown Source)
at java.net.URI.<init>(Unknown Source)
at com.someOrg.SomePrj.SomeService.SomeService.<init>(SomeService.java:26)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148)
... 43 more
In the Service class, when I replace the line:
private String aURIString;
with the line
private String aURIString = "www.google.com"
it works fine though!
It, also, works fine and the #Required property is injected from the properties file if I empty the constructor and take the line:
oamURI = new URI(aURIString);
to a member method instead of the constructor
I need the #Required property in the constructor though!!!!!
Can somebody tell a means to make sure that the context injects the #Required property before calling the #Service class constructor, so it is available when the service constructor is called by the spring context?
There is no way to make value injected via setter available in constructor.
You can:
Use constructor injection instead:
#Autowired
public SomeService(#Value("${someUrl}") String aURIString) throws Exception { ... }
Use #PostConstruct instead of constructor for initialization code that depends on injected values:
#PostConstruct
public void init() throws Exception { ... }
Convert injected value in a setter instead of doing it in constructor:
#Required
#Value("${someUrl}")
public void setaURIString(String aURIString) throws Exception {
try {
oamURI = new URI(aURIString);
} catch (URISyntaxException e) {
throw new Exception("URISyntaxException created while creating a URI instance for url= "+aURIString);
}
}

Resources