spring-Bean management-springboot principle-Maven advanced
configuration priority
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
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
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
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.
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)
2. Inheritance and Aggregation
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
If the parent and child projects are configured with different versions of the same dependency, the child project shall prevail.
< 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)
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
2. Resource upload and download
To use a private server, you need to do the following configuration in maven's settings.xml configuration file:
-
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>
-
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>
-
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>
-
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>
-
Publish the project and run the deploy life cycle directly (when publishing, it is recommended to skip the unit test)