Spring、Bean 创建 和 使⽤

news2024/9/24 7:24:04

目录

前言

1、创建 Spring 项目

1.1、创建一个 Maven 项目

1.2、在 Maven 项目中,添加 Spring 框架支持(spring-context,spring-beans)

1.2.1添加依赖

 1.2.2 配置国内源 

1.2.3 添加maven

1.3、创建一个启动类 和 main 方法

 2、将 Bean 对象存储到容器(Spring)中

2.1  添加配置文件 【如果是第一添加Bean对象】

 2.2 创建⼀个 Bean

2.3 在配置文件中,将需要保存到 spring中的 bean 对象进行注册

3、从 Spring 中,将 Bean 对象读取出来

3.1、得到 Spring 上下文对象

3.2、通过 上下文对象提供的方法,获取 我们自己需要使用的 bean 对象

3.3、拿到 bean 对象之后,就可以调用 里面的方法。

拓展

ApplicationContext 与 BeanFactory 的区别

总结


前言

经过前面 Spring 核心 与 设计思想的学习,我们已经知道了:Spring 就是一个包含众多工具方法的 IoC 容器。
既然是容器,那额它就具有两个核心功能:

        1、将对象(Bean) 存储到容器中
        2、从容器中将对象(Bean)去出来

本文主要讲解的重点:

        1、创建项目
        2、将对象存储到 Spring
        3、从 Spring中取出对象 

1、创建 Spring 项目

接下来使用 Maven 方式 来创建一个 Spring 项目。
创建 Spring 项目 和 Servlet 相似。
总共分为以下 3 步:

1、创建一个普通 Maven 项目
其实 Spring Boot 也是基于 Maven 来实现的,只不过 Spring 需要我们自己去创建,而 Spring Boot 直接内置了。

2、在 Maven 项目中,添加 Spring 框架支持(spring-context,spring-beans)

3、创建一个启动类,并添加 main 方法。
其实第三步是一个非必要操作,但是我们后面需要去测试 Bean(对象)的存入 与 取出的。
因此,我们需要一个可以测试的类,
故:需要创建一个启动类(测试的类)和 main,而不是依靠 Tomcat 的错误提示。
如果你是创建的一个 Spring Web,或者 Spring MVC,那需要依靠Tomcat。
而我们现在创建的项目是 Spring Core 。
core 核心项目,也就是最基础的核心项目。
所以,我们不需要依靠 Tomcat,就一个类就可以了。

注意!我们现在学习的是 Spring,不是 Spring Boot。
Spring 是在 Spring Boot 之前的框架。
因此,Spring 操作起来。没有像 Spring Boot 那么方便!
难度,和 servlet 差不多。

凡事都要一个过程。
最初的框架,并没有那么好用。
总有一个发展的过程。
很显然,Spring 属于前者,Spring Boot 属于后者。
 

1.1、创建一个 Maven 项目

1.2、在 Maven 项目中,添加 Spring 框架支持(spring-context,spring-beans)

1.2.1添加依赖

直接复制粘贴到 pom.xml 文件中即可。

<dependencies>
   <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>5.2.3.RELEASE</version>
    </dependency>
  
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>5.2.3.RELEASE</version>
    </dependency>
</dependencies>


 1.2.2 配置国内源 

另外,一定要配置 国内的源!!!!!
就算此时不出问题,以后也会出问题!

如果你还是使用默认的国外源
尤其是创建 Spring Boot 项目,引入依赖的时候,及其容易翻车!

如果你有 settings.xml 文件,就把上面框选的部分,手动拷贝进去。 

      <mirror>
        <id>alimaven</id>
        <name>aliyun maven</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
        <mirrorOf>central</mirrorOf>        
      </mirror> 

 如果你的文件中没有settings.xml,说明你之前没有配置过,新建文件,取名为settings.xml,然后把下面的代码复制进去

<?xml version="1.0" encoding="UTF-8"?>

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->

<!--
 | This is the configuration file for Maven. It can be specified at two levels:
 |
 |  1. User Level. This settings.xml file provides configuration for a single user,
 |                 and is normally provided in ${user.home}/.m2/settings.xml.
 |
 |                 NOTE: This location can be overridden with the CLI option:
 |
 |                 -s /path/to/user/settings.xml
 |
 |  2. Global Level. This settings.xml file provides configuration for all Maven
 |                 users on a machine (assuming they're all using the same Maven
 |                 installation). It's normally provided in
 |                 ${maven.conf}/settings.xml.
 |
 |                 NOTE: This location can be overridden with the CLI option:
 |
 |                 -gs /path/to/global/settings.xml
 |
 | The sections in this sample file are intended to give you a running start at
 | getting the most out of your Maven installation. Where appropriate, the default
 | values (values used when the setting is not specified) are provided.
 |
 |-->
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <!-- localRepository
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ${user.home}/.m2/repository
  <localRepository>/path/to/local/repo</localRepository>
  -->

  <!-- interactiveMode
   | This will determine whether maven prompts you when it needs input. If set to false,
   | maven will use a sensible default value, perhaps based on some other setting, for
   | the parameter in question.
   |
   | Default: true
  <interactiveMode>true</interactiveMode>
  -->

  <!-- offline
   | Determines whether maven should attempt to connect to the network when executing a build.
   | This will have an effect on artifact downloads, artifact deployment, and others.
   |
   | Default: false
  <offline>false</offline>
  -->

  <!-- pluginGroups
   | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
   | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
   | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
   |-->
  <pluginGroups>
    <!-- pluginGroup
     | Specifies a further group identifier to use for plugin lookup.
    <pluginGroup>com.your.plugins</pluginGroup>
    -->
  </pluginGroups>

  <!-- proxies
   | This is a list of proxies which can be used on this machine to connect to the network.
   | Unless otherwise specified (by system property or command-line switch), the first proxy
   | specification in this list marked as active will be used.
   |-->
  <proxies>
    <!-- proxy
     | Specification for one proxy, to be used in connecting to the network.
     |
    <proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <username>proxyuser</username>
      <password>proxypass</password>
      <host>proxy.host.net</host>
      <port>80</port>
      <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>
    -->
  </proxies>

  <!-- servers
   | This is a list of authentication profiles, keyed by the server-id used within the system.
   | Authentication profiles can be used whenever maven must make a connection to a remote server.
   |-->
  <servers>
    <!-- server
     | Specifies the authentication information to use when connecting to a particular server, identified by
     | a unique name within the system (referred to by the 'id' attribute below).
     |
     | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
     |       used together.
     |
    <server>
      <id>deploymentRepo</id>
      <username>repouser</username>
      <password>repopwd</password>
    </server>
    -->

    <!-- Another sample, using keys to authenticate.
    <server>
      <id>siteServer</id>
      <privateKey>/path/to/private/key</privateKey>
      <passphrase>optional; leave empty if not used.</passphrase>
    </server>
    -->
  </servers>

  <!-- mirrors
   | This is a list of mirrors to be used in downloading artifacts from remote repositories.
   |
   | It works like this: a POM may declare a repository to use in resolving certain artifacts.
   | However, this repository may have problems with heavy traffic at times, so people have mirrored
   | it to several places.
   |
   | That repository definition will have a unique id, so we can create a mirror reference for that
   | repository, to be used as an alternate download site. The mirror site will be the preferred
   | server for that repository.
   |-->
  <mirrors>
   <mirror>
        <id>alimaven</id>
        <name>aliyun maven</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
        <mirrorOf>central</mirrorOf>        
      </mirror>
    <!-- mirror
     | Specifies a repository mirror site to use instead of a given repository. The repository that
     | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
     |
    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror>
     -->
  </mirrors>

  <!-- profiles
   | This is a list of profiles which can be activated in a variety of ways, and which can modify
   | the build process. Profiles provided in the settings.xml are intended to provide local machine-
   | specific paths and repository locations which allow the build to work in the local environment.
   |
   | For example, if you have an integration testing plugin - like cactus - that needs to know where
   | your Tomcat instance is installed, you can provide a variable here such that the variable is
   | dereferenced during the build process to configure the cactus plugin.
   |
   | As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles
   | section of this document (settings.xml) - will be discussed later. Another way essentially
   | relies on the detection of a system property, either matching a particular value for the property,
   | or merely testing its existence. Profiles can also be activated by JDK version prefix, where a
   | value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.
   | Finally, the list of active profiles can be specified directly from the command line.
   |
   | NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact
   |       repositories, plugin repositories, and free-form properties to be used as configuration
   |       variables for plugins in the POM.
   |
   |-->
  <profiles>
    <!-- profile
     | Specifies a set of introductions to the build process, to be activated using one or more of the
     | mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>
     | or the command line, profiles have to have an ID that is unique.
     |
     | An encouraged best practice for profile identification is to use a consistent naming convention
     | for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.
     | This will make it more intuitive to understand what the set of introduced profiles is attempting
     | to accomplish, particularly when you only have a list of profile id's for debug.
     |
     | This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.
    <profile>
      <id>jdk-1.4</id>

      <activation>
        <jdk>1.4</jdk>
      </activation>

      <repositories>
        <repository>
          <id>jdk14</id>
          <name>Repository for JDK 1.4 builds</name>
          <url>http://www.myhost.com/maven/jdk14</url>
          <layout>default</layout>
          <snapshotPolicy>always</snapshotPolicy>
        </repository>
      </repositories>
    </profile>
    -->

    <!--
     | Here is another profile, activated by the system property 'target-env' with a value of 'dev',
     | which provides a specific path to the Tomcat instance. To use this, your plugin configuration
     | might hypothetically look like:
     |
     | ...
     | <plugin>
     |   <groupId>org.myco.myplugins</groupId>
     |   <artifactId>myplugin</artifactId>
     |
     |   <configuration>
     |     <tomcatLocation>${tomcatPath}</tomcatLocation>
     |   </configuration>
     | </plugin>
     | ...
     |
     | NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to
     |       anything, you could just leave off the <value/> inside the activation-property.
     |
    <profile>
      <id>env-dev</id>

      <activation>
        <property>
          <name>target-env</name>
          <value>dev</value>
        </property>
      </activation>

      <properties>
        <tomcatPath>/path/to/tomcat/instance</tomcatPath>
      </properties>
    </profile>
    -->
  </profiles>

  <!-- activeProfiles
   | List of profiles that are active for all builds.
   |
  <activeProfiles>
    <activeProfile>alwaysActiveProfile</activeProfile>
    <activeProfile>anotherAlwaysActiveProfile</activeProfile>
  </activeProfiles>
  -->
</settings>

配置好了,可以用 VSCode ,再来打开这个文件。
来查看一下,有没有配置的代码
有,就说明国内源,完全配置好了。


还没有完,此时我们设置的,只是针对当前项目。 还需要对之后新建的项目进行配置

另外,还有一个特殊的情况,在我们配置化好了之后。
仍然,下载依赖失败,或者代码运行有问题。
这是因为 你的 jar包(依赖)下载缺失,锁导致的问题。 

如果你还是失败,那就是你自己网络的问题了!过会再试试

1.2.3 添加maven

在pom.xml中添加以下代码

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


        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>5.2.3.RELEASE</version>
        </dependency>


1.3、创建一个启动类 和 main 方法

在 java目录下,创建一个 Java类。
名字随意,至于类的内容,暂时写成下方中的内容


 2、将 Bean 对象存储到容器(Spring)中

要实现这个目的,我们需要 两个 或 三 个 步骤。

为什么,这里要有个或呢?
换个说法:到底是2个,还是3个步骤呢?
这个是取决于 你 添加的这个 Bean 对象,是第一次添加,还是非第一次添加。

如果是 第一次添加,那么,有三个步骤:
1、在 Spring 项目中 添加配置文件【非第一次,此步骤可以省略】

2、存储 Bean 之前,先得有 Bean 才⾏,因此先要创建⼀个 Bean。

3、在配置文件中,将需要保存到 spring中的 bean 对象进行注册。 

2.1  添加配置文件 【如果是第一添加Bean对象】

和 Servlet 配置 web,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">

</beans>

将上述的 代码进行拷贝,进行如下操作。


 2.2 创建⼀个 Bean

所谓的 Bean 对象,其实就是 Java 中的普通类。
只不过 权限是由 spring 所持有。


2.3 在配置文件中,将需要保存到 spring中的 bean 对象进行注册

我们需要对 spring-config.xml 配置文件,进行如下操作。

就和我们在 pom.xml 中一样,dependency标签是具体用来引入依赖的标签,而 dependencies 就是 dependency的容器。这就不就印证了那句话: spring 是 一个 存储 loC (控制反转)的容器。其实就是存储控制反转的 对象 (Bean)


3、从 Spring 中,将 Bean 对象读取出来

读取操作,可分为三步:
1、先得到 spring 上下文对象

就是你要读取 Spring 里面的东西,需要先得到 Spring。
你可以这么认为:上下文对象 等价于 Spring

2、得到Spring上下文对象之后,再通过 上下文对象提供的方法,获取 我们自己需要使用的 bean 对象

3、拿到 bean 对象之后,就可以调用 里面的方法。

拿到 bean 对象之后,就可以使用 bean 对象了。


3.1、得到 Spring 上下文对象

3.2、通过 上下文对象提供的方法,获取 我们自己需要使用的 bean 对象

3.3、拿到 bean 对象之后,就可以调用 里面的方法。

此时,获取到 bean 对象,也就是 User 类的对象。
里面包含着,此次我们需要调用的 sayHi 方法。


 注意事项1

 快速锁定异常位置的技巧Ctrl + F : 搜索功能

注意事项2

因为 编辑器 产生运行缓存。
你的运行结果,它直接照搬 上次运行出错的状态。
我们需要做的就是:将 target 目录删除,重新执行程序即可。

准确来说:target目录,和 servlet 一样,就是 JVM 运行的目录。
这个目录,是自动生成的。
根据项目中的 源代码 和 资源文件,自己去生成一个 target文件的。
而且,你展开 target 目录,就会发现 和 上面的目录结构,完全是一样的。

 注意事项3

Bean 的 Id 要⼀⼀对应

拓展

除了 ApplicationContext 之外,我们还可以使⽤ BeanFactory 来作为 Spring 的上下文

BeanFactory -> Bean Factory(Bean对象工厂)

既然 BeanFactory 可以达到 ApplicationContext 相同的效果。
那么,这两者之间又有什么区别?
这可以非常经典的面试题哦!!!!!

ApplicationContext 与 BeanFactory 的区别

相同点:
        1、都提供了getBean 方法

不同点:
        1、ApplicationContext 是 BeanFactory 的子类,因此 ApplicationContext 所具有的方法,肯定是比 BeanFactory 多的。因此在 Java 中,子类继承父类,将会拥有父类的一切(子承父业),而且自己自身还自带了一些方法。两者一累加,子类 ApplicationContext 中的方法,自然也就比 父类 BanFactory 多了。BeanFactory 只提供了基础访问 Bean 的方法,而 ApplicationContext 除了拥有 BeanFactory 的所有功能之外,还提供了更多的方法实现。比如:添加了对国际化支持、资源访问支持、以及事件传播等方面的支持。

        2、性能:从性能方面来说:两者是不一样的!ApplicationContext 是一次性加载并初始化所有的 Bean 对象而 BeanFactory是需要,才去加载的(按需加载->懒加载)。因此更加轻量。这两种方式,各有优点。
        像BeanFactory,这种懒加载读取 Bean 对象的方式,是很低效的,但是对于 系统的开销是非常小的,毕竞不用一次性加载全部的 Bean 对象。之所以说:读取 Bean对象的速度很慢,是因为 第一次读取 Bean 对象的时候,是需要 将 pom.xml 中的 bean 对象存入 Spring的,然后才能从 Spring 中取出它。因此,像懒加载这种,如果使用的每个 Bean 对象,都是第一次使用,那就非常影响访问的速度。

        ApplicationContext 虽然是一次性加载并初始化所有的 Bean 对象,对于系统的开销比较大,但是后面需要用到 bean 对象的时候,直接拿,不需要在加载 Bean 对象了。获取对象 Bean 的速度,非常快!在性能这一点,大部分用户 对于 访问的速度,更加偏爱因此 ApplicationContext 的加载方式,更受人们的喜爱。毕竟现在的人,追求效率。并不会关注系统背后做了些什么。
那么,问题来了: ApplicationContext 和 BeanFactory,那一个更好呢?
这就得根据实际情况来看了。
如果是以性能至上的场景,Application首选。反之,以 稳定性 为主,BeanFactory是首选。

下面,我们来通过代码来模拟验证一下。
BeanFactory 究竟是不是 懒加载
ApplicationContext 是不是 一次性将 bean 对象,全部加载。

 getBean 方法的更多用法

getBean() ⽅法有很多种重载⽅法,我们也可以使⽤其他⽅式来获取 Bean 对象.

这是 ApplicationContext 的所提供的 getBean 方法

 BeanFactory 用的还是很少的,所以,我们以 ApplicationContext 为主

 1、使用 bean id 获取 bean对象。

这个就是我们上面所使用的方法

 2、根据 bean 的 类型 来获取 bean对象

方法还是 getBean 方法,只是传的参数不同,

 3、第三种写法,属于 第一种 和 第二种 的 结合。

使用 Bean 的 id 和 对象类型(两个参数)来锁定唯一的对象(bean)。

 第三种写法,是最推荐的!
因为 它 最稳。

总结

本文重点有三大点:

1、操作容器之前,先要有容器,所以先要得到容器。
  1.1、创建 maven项目
  1.2、添加 Spring 框架支持,引入 spring-context 和 spring-beans 依赖
  1,3、创建一个启动类 和 main方法

2、存对象
  2.1、创建 Bean(普通类)
  2.2、将 Bean 注册(配置)到 spring-config.xml 中。【bean标签】

3、取对象
  3.1、得到 Spring 上下文对象,并读取到 Spring 的配置文。【ApplicationContext】
  3.2、获取某一个bean(对象)
  3.3、使用 Bean(对象)

操作流程图 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/696840.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Mybatis 操作数据库的基本 CRUD 以及查询操作详析

目录 1. 什么是 MyBaits &#xff1f; 2. 搭建 MyBaits 环境 3. 了解 MyBaits 设计模式 MyBaits 操作数据库&#xff1a; 前置工作&#xff1a; &#xff08;1&#xff09;建库建表 &#xff08;2&#xff09; 添加实体类 &#xff08;3&#xff09;添加 Mapper 接口 &#xff…

CPU上下文切换原理剖析

CPU上下文 CPU上下文其实是一些环境正是有这些环境的支撑&#xff0c;任务得以运行&#xff0c;而这些环境的硬件条件便是CPU寄存器和程序计数器。CPU寄存器是CPU内置的容量非常小但是速度极快的存储设备&#xff0c;程序计数器则是CPU在运行任何任务时必要的&#xff0c;里面…

亿级数据过滤算法----布隆过滤器

在程序的世界中&#xff0c;布隆过滤器是程序员的一把利器&#xff0c;利用它可以快速地解决项目中一些比较棘手的问题。如网页 URL 去重、垃圾邮件识别、大集合中重复元素的判断和缓存穿透等问题。 布隆过滤器&#xff08;Bloom Filter&#xff09;是 1970 年由布隆提出的。它…

水站桶装水订水小程序

水站桶装水订水小程序正式上线&#xff0c;支持多种商品展示形式&#xff0c;会员卡、积分、分销等功能&#xff0c;有需要的老板可以先看演示&#xff01;​​​​​​​​​​​​​​​​​​​​​

Java框架之spring 的 messaging

写在前面 本文看下spring message相关的内容。 1&#xff1a;Message&#xff1f;Messaging&#xff1f; Message是消息的意思&#xff0c;是一个名词。而Messaging是一个动名词&#xff0c;是将消息发送出去的意思&#xff0c;因此&#xff0c;我们的消息系统是messaging s…

SuperMap iServer 扩展账户信息合规度校验规则

作者&#xff1a;lisong 目录 功能简介配置文件详情扩展和配置流程 功能简介 SuperMap iServer 11i&#xff08;2023&#xff09; 新增了扩展账户信息合规度校验规则的能力&#xff0c;您可以灵活定制满足自身项目需求的用户名、密码合规度校验规则&#xff0c;用于校验您创建…

企业邮箱如何修改管理员密码

1、登录企业邮局&#xff0c;点击顶部“邮局管理”。在邮局管理中点击“组织与成员”,在用户列表中&#xff0c;点击“邮局管理员”&#xff08;postmaster&#xff09;。 2、在编辑用户中&#xff0c;点击“重置密码”,然后输入新的密码&#xff0c;保存即可。

java中的xxl-job-core完成定时任务的步骤

首先这个是基于docker的所以需要进行docker配置 1、先导入官方提供的SQL到虚拟机中mysql中 2、创建容器 docker run -e PARAMS"--spring.datasource.urljdbc:mysql://192.168.211.136:3306/xxl_job?useUnicodetrue&characterEncodingUTF-8&autoReconnecttrue&a…

2014年全国硕士研究生入学统一考试管理类专业学位联考数学试题——纯题目版

2014 年考研管理类联考数学真题 一、问题求解&#xff08;本大题共 15 小题&#xff0c;每小题 3 分&#xff0c;共 45 分&#xff09;下列每题给出 5 个选项中&#xff0c;只有一个是符合要求的&#xff0c;请在答题卡上将所选择的字母涂黑。 1.某部门在一次联欢活动中共设了 …

python接口自动化测试 - configparser配置文件解析器详细使用

configparser简介 ConfigParser模块已在Python 3中重命名为configparser该模块定义了ConfigParser类。 ConfigParser类实现一种基本的配置文件解析器语言&#xff0c;该语言提供的结构类似于 .ini 文件中的结构 Python自动化测试&#xff1a;手把手教你做60个实战项目&#xf…

设计模式(二十三)——解释器模式(Interpreter )

解释器模式&#xff08;Interpreter &#xff09; 实现了一个表达式接口&#xff0c;该接口解释一个特定的上下文 应用 编译器&#xff0c;正则表达式&#xff0c;SQL解析 实现 实现一个一位数的加法运算 public class Interpreter {public int add(String s){if (s.char…

代码复现:基于精英动态反向学习的增强型正余弦算法—EDOLSCA,可用于对比试验

代码复现&#xff1a;基于精英动态反向学习的增强型正余弦算法—EDOLSCA&#xff0c;可用于对比试验。 参考文献&#xff1a;Zhang L, Hu T, Yang Z, et al. Elite and dynamic opposite learning enhanced sine cosine algorithm for application to plat-fin heat exchanger…

带你用Python制作超级经典的2048游戏(文末赠书)

名字&#xff1a;阿玥的小东东 学习&#xff1a;Python、C/C 主页链接&#xff1a;阿玥的小东东的博客_CSDN博客-python&&c高级知识,过年必备,C/C知识讲解领域博主 目录 2048游戏Python实现 本期赠书 2048游戏Python实现 2048游戏是一款非常流行的益智游戏&#xff0…

vue-cli的Nuxt重构

我的博客用vuecli写的&#xff0c;SEO不忍直视。于是用Nuxt重构了代码&#xff0c;过程中踩了无数坑 一&#xff1a;body样式不生效 正常的body样式设置不能生效&#xff0c;需要在nuxt.config.js中配置 1、设置bodyAttrs的class属性&#xff0c;该属性值对应一个类名 2、该…

Unity 聚焦任意大小的物体

聚焦任意大小的物体 &#x1f371;效果&#x1f96a;食用方法 &#x1f371;效果 &#x1f96a;食用方法 &#x1f4a1;.安装Cinemachine &#x1f4a1;.把Assets/ZYF/Tools/Camera/Scene/FocusGo/FocusCtrl.prefab拖入场景 &#x1f4a1;.调用FocusCtrl.Focus(gameObject)即可…

《kafka 核心技术与实战》课程学习笔记(九)

客户端都有哪些不常见但是很高级的功能&#xff1f; 什么是 Kafka 拦截器&#xff1f; 拦截器基本思想就是允许应用程序在不修改逻辑的情况下&#xff0c;动态地实现一组可插拔的事件处理逻辑链。它能够在主业务操作的前后多个时间点上插入对应的“拦截”逻辑。Spring MVC 拦…

接口跨域问题

只要协议不同/端口号不同/域名不同都会导致跨域问题

深入浅出设计模式 - 中介者模式

博主介绍&#xff1a; ✌博主从事应用安全和大数据领域&#xff0c;有8年研发经验&#xff0c;5年面试官经验&#xff0c;Java技术专家✌ Java知识图谱点击链接&#xff1a;体系化学习Java&#xff08;Java面试专题&#xff09; &#x1f495;&#x1f495; 感兴趣的同学可以收…

C++之lambda表达式回调函数作为参数(一百四十)

简介&#xff1a; CSDN博客专家&#xff0c;专注Android/Linux系统&#xff0c;分享多mic语音方案、音视频、编解码等技术&#xff0c;与大家一起成长&#xff01; 优质专栏&#xff1a;Audio工程师进阶系列【原创干货持续更新中……】&#x1f680; 人生格言&#xff1a; 人生…

【python】matplotlib 绘制火山图、条形图

文章目录 火山图条形图 火山图 绘制火山图&#xff0c;输入是两个datafreme&#xff0c;行是样本名&#xff0c;列是基因名。使用T-test检验绘制基因表达情况。 def minmax_scale(data):import numpy as np# # 示例数据# data np.array([2, 4, 6, 8, 10])# 进行Min-Max标准化…