PDA

View Full Version : Inject ServiceBean to Servlet failed


wangyi
Jun 2nd, 2006, 12:44 PM
Hello,

I am developing a webap with spring. I am using spring mvc, and integrate with service provided by other people. Service is a jar file, I put it under : /WEB-INF/lib/. After I start my tomcat, I got the following errors:

"MementosInputController" is going to invoke MementosService, however, it fails to create MementosService Bean because of no init() defined.

// INJECTED
private MementoService mementoService;
public void setMementoService(MementoService mementoService) {
this.mementoService = mementoService;
}



2006-06-02 09:31:41 StandardContext[/SparksWeb]Loading Spring root WebApplicationContext
2006-06-02 09:31:42 StandardContext[/SparksWeb]Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListe ner
org.springframework.beans.factory.BeanCreationExce ption:

Error creating bean with name 'MementosInputController' defined in ServletContext resource [/WEB-INF/metricsapp-servlet.xml]:

Cannot create inner bean 'com.schwab.sparks.metricsui.service.MementoServic e#28305d'
while setting bean property 'mementoService'; nested exception is org.springframework.beans.factory.BeanCreationExce ption:

Error creating bean with name 'com.schwab.sparks.metricsui.service.MementoServic e#28305d' defined in ServletContext resource [/WEB-INF/metricsapp-servlet.xml]:

Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [com.schwab.sparks.metricsui.service.MementoService]:

No default constructor found; nested exception is java.lang.NoSuchMethodException: com.schwab.sparks.metricsui.service.MementoService .<init>()

Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'com.schwab.sparks.metricsui.service.MementoServic e#28305d' defined in ServletContext resource [/WEB-INF/metricsapp-servlet.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [com.schwab.sparks.metricsui.service.MementoService]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.schwab.sparks.metricsui.service.MementoService .<init>()
Caused by: org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [com.schwab.sparks.metricsui.service.MementoService]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.schwab.sparks.metricsui.service.MementoService .<init>()
Caused by: java.lang.NoSuchMethodException: com.schwab.sparks.metricsui.service.MementoService .<init>()

Could anyone give me some suggestions?

Thanks very much

Yi

Mark Fisher
Jun 2nd, 2006, 01:36 PM
The MementoService is not being instantiated because it lacks a default (no-arg) constructor. You either need to provide a default constructor or use constructor injection to satisfy an existing constructor.