java代码:
package com.init;import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;public class Bean implements BeanPostProcessor {
private String name; /**
* @return the name
*/
public String getName() {
return name;
} public void init() {
System.out.println("this is init method");
} /**
* @param name
* the name to set
*/
public void setName(String name) {
this.name = name;
} public Object postProcessAfterInitialization(Object arg0, String arg1)
throws BeansException {
System.out.println("postProcessAfterInitialization");
return arg0;
} public Object postProcessBeforeInitialization(Object arg0, String arg1)
throws BeansException {
System.out.println("postProcessAfterInitialization");
return arg0;
} public void sayHello() {
System.out.println("hello ");
} public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext(
"init.xml");
Bean bean = (Bean) context.getBean("bean");
bean.sayHello();
}}xml文件 :<?xml version="1.0" encoding="GB18030"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
"> <bean id="bean" class="com.init.Bean" init-method="init">
<property name="name">
<value>testName</value>
</property>
</bean></beans>
感谢回复者,祝你连同你的家人快乐。
package com.init;import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;public class Bean implements BeanPostProcessor {
private String name; /**
* @return the name
*/
public String getName() {
return name;
} public void init() {
System.out.println("this is init method");
} /**
* @param name
* the name to set
*/
public void setName(String name) {
this.name = name;
} public Object postProcessAfterInitialization(Object arg0, String arg1)
throws BeansException {
System.out.println("postProcessAfterInitialization");
return arg0;
} public Object postProcessBeforeInitialization(Object arg0, String arg1)
throws BeansException {
System.out.println("postProcessAfterInitialization");
return arg0;
} public void sayHello() {
System.out.println("hello ");
} public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext(
"init.xml");
Bean bean = (Bean) context.getBean("bean");
bean.sayHello();
}}xml文件 :<?xml version="1.0" encoding="GB18030"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
"> <bean id="bean" class="com.init.Bean" init-method="init">
<property name="name">
<value>testName</value>
</property>
</bean></beans>
感谢回复者,祝你连同你的家人快乐。
解决方案 »
- 过滤器导致网站变乱
- 现在要做个可以下载音乐的服务端,请问用什么平台和语言能迅速开发出基本的功能
- 如何把结果集存入outputStream
- 为什么连接数MSsql2000据库正确,并且能有正确运行,但仍然 提示错误
- 求助,关于编码的问题
- [散分了] 根据客服端代码写服务器代码(多线程)
- 有谁搞过James邮件服务器。有经验的人能进来帮我解决下问题。
- 紧急求救,请问各位高手如何在InstallShield X中进入脚本编辑界面。
- 上传图片的问题路径
- 求助各位大佬关于frameset跳转的问题
- 请高手解救小弟,万分感激!使用dom4j如何实现按Element的某个属性排序???
- 54260683 java web 高级交流群。欢迎大家加入
public Object postProcessAfterInitialization(Object arg0, String arg1)
throws BeansException {
System.out.println("postProcessAfterInitialization");
return arg0;
}public Object postProcessBeforeInitialization(Object arg0, String arg1)
throws BeansException {
System.out.println("postProcessAfterInitialization");
return arg0;
} 这两个方法没有被调用,是如何回事?
但是在楼主的定义文件中,只定义了一个bean,而且还是实现了BeanPostProcessor接口的Bean,我觉得问题应该是出现在这里,建议楼主把现有的Bean分为两个Bean试试,就是一个Bean用来实现BeanPostProcessor接口,然后另一个Bean用来配合实现了BeanPostProcessor接口的Bean。