java - Issues with BeanPostProcessor -
there issue using beanpostprocessor. error log says method josh() in productfactory class missing class have such method , non-static. below code snippets.
web.xml
<bean class="demoproject.productpostprocessor" /> <context:annotation-config /> <context:component-scan base-package="demoproject" /> <bean name="productfactory" class="demoproject.productfactory" />
productfactory.java
public class productcreater{ public static void main(string[] args) { applicationcontext context = new classpathxmlapplicationcontext("web.xml"); product copyproduct = (product) context.getbean("joshs"); system.out.println(copyproduct.getid()); system.out.println(copyproduct.getprice()); } }
productfactory.java
package demoproject; import org.springframework.beans.factory.annotation.value; import org.springframework.context.annotation.bean; import org.springframework.context.annotation.configuration; import org.springframework.context.annotation.lazy; @configuration public class productfactory { public productfactory() { // todo auto-generated constructor stub } @bean(name="joshs") public product josh(){ product josh = new battery(); josh.setid("cdrw"); return josh; } }
productpostprocessor.java
package demoproject; import org.springframework.beans.factory.config.beanpostprocessor; public class productpostprocessor implements beanpostprocessor{ public object postprocessbeforeinitialization(object bean, string beanname){ system.out.println("before initializing .. : "+beanname); return beanname; } public object postprocessafterinitialization(object bean, string beanname){ system.out.println("after initializing .. : "+beanname); return beanname; } }
error log
info: destroying singletons in org.springframework.beans.factory.support.defaultlistablebeanfactory@7b09df06: defining beans [demoproject.productpostprocessor#0,org.springframework.context.annotation.internalconfigurationannotationprocessor,org.springframework.context.annotation.internalautowiredannotationprocessor,org.springframework.context.annotation.internalrequiredannotationprocessor,org.springframework.context.annotation.internalcommonannotationprocessor,productfactory,productfactory,org.springframework.context.annotation.configurationclasspostprocessor.importawareprocessor,joshs]; root of factory hierarchy exception in thread "main" org.springframework.beans.factory.beancreationexception: error creating bean name 'joshs' defined in class path resource [demoproject/productfactory.class]: no matching factory method found: factory bean 'productfactory'; factory method 'josh()'. check method specified name exists , non-static.
somehow line <bean class="demoproject.productpostprocessor" />
in web.xml causing problem since when remove everyting works normally. how can debug program , fix it?
you're returning name of bean. postprocess
methods supposed return actual bean itself. you're telling spring replace product
bean string
containing name.
Comments
Post a Comment