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

米拓建站最新进展企业网站seo托管怎么做

米拓建站最新进展,企业网站seo托管怎么做,前端网页代码模板,企业qq出售平台目录 1.加载过程 2.示例: 3.注意: 1.加载过程 ①Bean 实例化 通过构造函数或工厂方法创建 Bean 的实例 ②手动设置属性 通过set方法进行赋值 ③属性注入 Spring 容器将配置的属性值注入到 Bean 中(通过 Autowired、Value、NacosValue…

目录

1.加载过程

2.示例:

3.注意:


1.加载过程

①Bean 实例化

通过构造函数或工厂方法创建 Bean 的实例

②手动设置属性

通过set方法进行赋值

③属性注入

Spring 容器将配置的属性值注入到 Bean 中(通过 @Autowired@Value@NacosValue 等注解或 XML 配置)。

④初始化

先调用调用 @PostConstruct 方法,再调用InitializingBeanafterPropertiesSet 方法,再调用自定义的初始化方法(通过 initMethod 指定)

⑤bean加载完成可以使用

⑥容器关闭时进行销毁

先调用 @PreDestroy 方法再调用 DisposableBeandestroy 方法。然后调用自定义的销毁方法(通过 destroyMethod 指定)

2.示例:

配置bean

package com.example.demo6.service;import lombok.Data;
import org.checkerframework.checker.units.qual.C;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;@Data
public class MyBean implements InitializingBean, DisposableBean {private Integer id;public MyBean() {System.out.println("执行无参构造1");}static {System.out.println("static1");}@Autowiredprivate MyBeans myBeans;@PostConstructpublic void postConstruct() {System.out.println("postConstruct1");}@Overridepublic void afterPropertiesSet() throws Exception {System.out.println("afterPropertiesSet1");}public void init() {System.out.println("init1");}@Overridepublic void destroy() throws Exception {System.out.println("afterPropertiesSet对应的销毁1");}@PreDestroypublic void preDestroy() {System.out.println("postConstruct对应的销毁1");}public void destroyMethod() {System.out.println("init对应的销毁1");}
}
package com.example.demo6.service;import lombok.Data;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.io.Serializable;@Data
public class MyBeans implements InitializingBean, DisposableBean {private Integer id;public MyBeans() {System.out.println("执行无参构造2");}static {System.out.println("static2");}@PostConstructpublic void postConstruct() {System.out.println("postConstruct2");}@Overridepublic void afterPropertiesSet() throws Exception {System.out.println("afterPropertiesSet2");}public void init() {System.out.println("init2");}@Overridepublic void destroy() throws Exception {System.out.println("afterPropertiesSet对应的销毁2");}@PreDestroypublic void preDestroy() {System.out.println("postConstruct对应的销毁2");}public void destroyMethod() {System.out.println("init对应的销毁2");}
}
package com.example.demo6.config;import com.example.demo6.service.MyBean;
import com.example.demo6.service.MyBeans;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;@Configuration
public class TestConfig {@Bean(initMethod="init",destroyMethod="destroyMethod")public MyBean myBean(){MyBean myBean = new MyBean();myBean.setId(1);System.out.println("属性赋值1");return myBean;}@Bean(initMethod="init",destroyMethod="destroyMethod")public MyBeans myBeans() {System.out.println("属性赋值2");return new MyBeans();}}

启动容器 

import com.example.demo6.config.TestConfig;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;public class Test {public static void main(String[] args) {System.out.println("容器启动");AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(TestConfig.class);System.out.println("加载完成");System.out.println("bean使用");context.close();}
}

 执行结果:


容器启动
22:21:50.639 [main] DEBUG org.springframework.context.annotation.AnnotationConfigApplicationContext - Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@5474c6c
22:21:50.649 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor'
22:21:50.789 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.event.internalEventListenerProcessor'
22:21:50.790 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.event.internalEventListenerFactory'
22:21:50.790 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor'
22:21:50.794 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalCommonAnnotationProcessor'
22:21:50.810 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'testConfig'
22:21:50.816 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'myBean'
static1
执行无参构造1
属性赋值1
22:21:50.839 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'myBeans'
static2
执行无参构造2
属性赋值2
postConstruct2
afterPropertiesSet2
init2
postConstruct1
afterPropertiesSet1
init1
加载完成
bean使用
22:21:50.859 [main] DEBUG org.springframework.context.annotation.AnnotationConfigApplicationContext - Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@5474c6c, started on Wed Mar 12 22:21:50 CST 2025
postConstruct对应的销毁1
afterPropertiesSet对应的销毁1
init对应的销毁1
postConstruct对应的销毁2
afterPropertiesSet对应的销毁2
init对应的销毁2

3.注意:

①静态代码块最先执行

②如果父类实现了InitializingBean接口,子类会执行父类的afterPropertiesSet方法,场景的动态数据源的实现类AbstractRoutingDataSource

③类的生命周期

  1. 加载(Loading)阶段:将类的字节码载入内存
  2. 链接(Linking)阶段
    1. 验证(Verification)确保 Class 文件的字节流符合 JVM 规范
    2. 准备(Preparation)为类的静态变量分配内存并设置初始值
    3. 解析(Resolution)将常量池中的符号引用替换为直接引用
  3. 初始化(Initialization)阶段
    1. 静态变量赋值
    2. 静态代码执行
  4. 使用(Using)阶段
    1. 类的实例化
    2. 属性注入
    3. 初始化方法执行
    4. 使用bean
  5. 卸载(Unloading)阶段
http://www.dtcms.com/wzjs/447017.html

相关文章:

  • 中国工程建设网站直通车推广
  • 中山市seo排名优化教程
  • 网站建设总体方案设计武汉seo公司
  • 专题网站建设方案最近七天的新闻重点
  • 营销技巧美剧第一季在线长春seo公司哪家好
  • 做网站要注意哪些销售平台排名
  • 做推广哪个网站效果好搜索引擎优化怎么做的
  • 做网站要找什么人网店如何推广
  • 营销型网站建设品牌百度下载官方下载安装
  • 郑州贴吧草根seo视频大全
  • 个人做网站有什么条件电工培训内容
  • 广州做网站的网络公司创意营销
  • 南京城乡住房建设厅网站郑州网站seo优化
  • 房地产网站模板 下载如何自己建一个网站
  • 福建亨立建设集团有限公司网站企业培训课程设置
  • 申请微官网的网站手机百度云网页版登录
  • 经营网站icp备案要求网上营销模式
  • 萌宝宝投票网站怎么做百度seo 优化
  • 口碑好的聊城网站建设成都网站优化及推广
  • 做网站如何来钱百度新版本更新下载
  • 少儿类网站怎么做凡客建站
  • 十大品牌排行榜前十名西安seo排名外包
  • 全国医院网站建设百度小说排行榜2019
  • 成都制作手机网站seo优化是什么职业
  • 建设工程方面的资料在哪个网站下载比较方便搜外seo
  • 青岛网站建设订做关键词推广操作
  • 村级网站建设系统百度关键词价格排行榜
  • 做编程的 网站有哪些域名是什么意思
  • 做网站广告收入青岛做网站推广公司
  • 做网站建设销售怎么制作自己的个人网站