当前位置: 首页 > news >正文

如何建立网站数据库连接济南网站建设抖音平台

如何建立网站数据库连接,济南网站建设抖音平台,wordpress外贸企业模板,做网站的公司哪家最好在Spring容器加入一个实现了BeanPostProcessor接口bean实例,重写postProcessBeforeInitialization、postProcessAfterInitialization方法,在方法里面写具体的实现,从而达到Spring容器在初如化前或销毁时执行预定的程序,方法如下&a…

在Spring容器加入一个实现了BeanPostProcessor接口bean实例,重写postProcessBeforeInitialization、postProcessAfterInitialization方法,在方法里面写具体的实现,从而达到Spring容器在初如化前或销毁时执行预定的程序,方法如下:

1、pop.xml导包
 

<dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>5.3.37</version>
</dependency>
<dependency>

2、写一个类实现BeanPostProcessor接口,同时写一个User实体类用于测试
实现类:

package test.spring.model;import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;public class LifeBeanAware implements BeanPostProcessor {@Overridepublic Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {// TODO Auto-generated method stubSystem.out.println("前置处理");return null;}@Overridepublic Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {// TODO Auto-generated method stubSystem.out.println("后置处理");return null;}}

User类:

/**
*Description:
*author: ljd
*@date 2024年7月2日 
*@version 1.0 
*/
package test.spring.model;public class User {private int id;private String name;public int getId() {return id;}public void setId(int id) {System.out.println("user赋值");this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public void testPrint() {System.out.println("this is test init function");}@Overridepublic String toString() {return "User [id=" + id + ", name=" + name + "]";}public User() {super();}}

3、applicationContext.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"><bean id="user1" init-method="testPrint" destroy-method="testPrint" class="test.spring.model.User" ><property name="id" value="1"></property><property name="name" value="zs"></property></bean><bean class="test.spring.model.LifeBeanAware"></bean>
</beans>


4、测试结果

/**
*Description:
*author: ljd
*@date 2024年7月2日 
*@version 1.0 
*/
package testSpring;import org.junit.Test;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;import test.spring.model.User;public class TestSpring {@Testpublic void testUser() {ConfigurableApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml");User user=ac.getBean(User.class); System.out.println(user);ac.close();}}

http://www.yayakq.cn/news/230597/

相关文章:

  • 2小时学会php网站建设重庆石柱网站设计公司
  • 静态网站优化wordpress图片怎么居中
  • 和动物做的网站吗wordpress购买资源插件
  • 百度app制作网站wordpress ftp 设置
  • 小网站推荐电商网站建设题库
  • 无忧中英繁企业网站系统通用版做网站如何选主机
  • 单站点网站量力商务大厦网站建设
  • 济南模板建站多少钱seo网站页面优化
  • 集团培训网站建设淮安设计网站
  • wordpress 分享网站成都系统开发
  • 如何对网站做实证分析台州响应式建站
  • 网站源码采集龙岗-网站建设深圳信科
  • 个人网站注册平台钱wordpress 大学网站
  • 17z一起做网站广州展示型网站 营销型网站
  • 移动网站mip杭州广告公司网站建设
  • 网站系统建设思想如何写重庆渝兴建设有限公司网站
  • 长沙建站最新人才招聘网
  • php sqlite 做网站wordpress更新要ftp
  • 松岗做网站价格网站开发 博客
  • 建站seo怎么赚钱单页网站上传教程
  • 建站快车来电可信网站是否有规定必须做
  • 免费数据源网站网眼搭建wordpress
  • 青岛微网站做后台系统的网站
  • 网站服务器和空间的区别网站平台被骗了怎么办
  • 西安住房和城乡建设部网站网站icon怎么做的
  • 怎么做网站加载动画秦洁婷seo博客
  • 做科技公司的网站公司做flash的网站
  • 三亚做民宿的都用什么网站西地那非片有依赖性吗
  • 自己做的网站打不开怎么搞百度搜索风云榜游戏
  • 哪里可以做购物网站建设工程质量检测管理办法