I have a Java Project which is written using Spring and am having trouble with @Autowire
of a bean. The declaration of the bean
<beans:bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<beans:property name="basenames" value="classpath:messages"/>
<beans:property name="defaultEncoding" value="UTF-8" />
</beans:bean>
The bean is being autowired without issue in my class BaseController
which falls under the component-scan
<context:component-scan base-package="com.myproj.webservice.controller" />
I want to @Autowire
in another class MessageEnum
which does not fall under the component-scan
. I have tried to add autowire="byType"
and autowire="byName"
to my bean declaration but the autowiring still did not work.
Please find here also my code for the MessageEnum
class
public enum MessageEnum{
ENUM1("someparam"),
ENUM2("someparam2");
@Autorwire
private MessageSource messageSource;
private String param;
//Constructors & getParam and setParam methods
public MessageSource getMessageSource() {
return messageSource;
}
}
What am I missing here for the messageSource
to be autowired?
EDIT
I tried to create the MessageEnum
as a bean as advised here. I created the default constructor
MessageEnum() {}
and set the bean in my xml
<beans:bean id="messageEnum" class="com.myproj.webservice.util.MessageEnum">
but receive the error message
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageEnum' defined in ServletContext resource [/WEB-INF/spring/appServlet/servlet-context.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.myproj.webservice.util.MessageEnum]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.myproj.webservice.util.MessageEnum.<init>()