spring-Bean management-springboot principle-Maven advanced

configuration priority

insert image description here
insert image description here

Priority (low→high)
application.yaml (ignore)
application.yml
application.properties
java system properties (-Dxxx=xxx)
command line parameters (–xxx=xxx)

Bean management

1. Get beans

insert image description here

The above-mentioned [When the Spring project starts, all the beans in it will be created] will also be affected by the scope and lazy initialization. This is mainly for the default singleton non-lazy loaded beans.

2. bean scope

insert image description here

The scope can be configured through the @Scope annotation: @Scope("prototype")
defaults to a singleton bean, which is created when the container starts, and can be initialized using the @Lazy annotation (delayed until the first use). The bean of prototype will create a new instance every time the bean is used.
In actual development, most beans are singletons, which means that most beans do not need to be configured with scope attributes.

3. Third-party beans

If the bean object to be managed comes from a third party (not custom), it is impossible to declare the bean with @Component and derived annotations, you need to use the @Bean annotation.

Principles of Spring Boot

The automatic configuration of SpringBoot is that when the spring container is started, some configuration classes and bean objects are automatically stored in the IOC container, and we do not need to declare it manually, which simplifies development and saves tedious configuration operations.
insert image description here
insert image description here

Maven Advanced

1. Sub-module design and development

The project is divided into several sub-modules according to the function, which is convenient for project management, maintenance and expansion, and also facilitates the mutual calling and resource sharing between modules. (Divide the project into several maven modules, introduce maven dependencies and call each other)

insert image description here

2. Inheritance and Aggregation

insert image description here

jar: Ordinary module packaging, springboot projects are basically jar packages (embedded tomcat running)
war: Ordinary web programs are packaged and need to be deployed and run on an external tomcat server
pom: parent project or aggregation project, this module does not write code, only for dependency management

insert image description here

If the parent and child projects are configured with different versions of the same dependency, the child project shall prevail.

insert image description here

< dependencies > is a direct dependency. If the dependency is configured in the parent project, the child project will inherit it directly.
< dependencyManagement > is a unified management dependency version, not directly dependent, but also needs to introduce the required dependencies in the sub-project (no need to specify the version)

insert image description here
insert image description here

effect:
Aggregation is used to quickly build projects
Inheritance is used to simplify dependency configuration and manage dependencies uniformly
Same point:
The pom.xml files of aggregation and inheritance are packaged in pom, and the two relationships can be made into the same pom file. Both
aggregation and inheritance belong to design modules, and there is no actual module content
difference:
Aggregation is to configure the relationship in the aggregation project. Aggregation can perceive which modules participate in the aggregation.
Inheritance is to configure the relationship in the sub-module. The parent module cannot perceive which sub-modules inherit itself

3. Private server

1 Introduction

insert image description here

2. Resource upload and download

insert image description here
To use a private server, you need to do the following configuration in maven's settings.xml configuration file:

  1. You need to configure the personal credentials for accessing the private server (username and password for access) in the servers tab

    <server>
        <id>maven-releases</id>
        <username>admin</username>
        <password>admin</password>
    </server>
        
    <server>
        <id>maven-snapshots</id>
        <username>admin</username>
        <password>admin</password>
    </server>
    
  2. Only configure the connection address of our own private server in mirrors (if Alibaba Cloud has been configured before, it needs to be replaced directly)

    <mirror>
        <id>maven-public</id>
        <mirrorOf>*</mirrorOf>
        <url>http://192.168.150.101:8081/repository/maven-public/</url>
    </mirror>
    
  3. It is necessary to add the following configuration in the profiles to specify the dependency of the snapshot snapshot version, and it is still allowed to use

<profile>
    <id>allow-snapshots</id>
        <activation>
        	<activeByDefault>true</activeByDefault>
        </activation>
    <repositories>
        <repository>
            <id>maven-public</id>
            <url>http://192.168.150.101:8081/repository/maven-public/</url>
            <releases>
            	<enabled>true</enabled>
            </releases>
            <snapshots>
            	<enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>
</profile>
  1. If you need to upload your own project to the private server, you need to add the following configuration in the pom.xml file of the project to configure the address of the project release (that is, the address of the private server)

    <distributionManagement>
        <!-- release版本的发布地址 -->
        <repository>
            <id>maven-releases</id>
            <url>http://192.168.150.101:8081/repository/maven-releases/</url>
        </repository>
        
        <!-- snapshot版本的发布地址 -->
        <snapshotRepository>
            <id>maven-snapshots</id>
            <url>http://192.168.150.101:8081/repository/maven-snapshots/</url>
        </snapshotRepository>
    </distributionManagement>
    
  2. Publish the project and run the deploy life cycle directly (when publishing, it is recommended to skip the unit test)

Supongo que te gusta

Origin blog.csdn.net/m0_59230408/article/details/130024359
Recomendado
Clasificación