Springboot project, you can configure project-related information through the Application.properties configuration file.
Application.properties project configuration file, open is blank inside can be configured items, so configuration items we alt+/can prompt out
Previous Tomcat default port 8080 The default path is the root directory/
We now change to port 8888 and the context path/helloworld
Save after change, start Helloworldapplication class
Page Input: Http://localhost:8888/HelloWorld/hello
The results come out.
Springboot Support for custom attributes
We add a HelloWorld attribute to the Application.properties property value Spring Boot Hello
Of course, the Chinese byte encoding processing
Page we define and then configure a property value, call the request, you can return the configured value directly.
This is a very good function, more convenient;
We restart the Helloworldapplication class,
Page Input: Http://localhost:8888/HelloWorld/hello
Show:
If we want to configure multiple properties under a category,
such as MySQL's JDBC connection configuration
Mysql.jdbcname=com.mysql.jdbc.driver
Mysql.dburl=jdbc:mysql://localhost:3306/db_diary
Mysql.username=root
mysql.password=123456
We'll stick to application.properties.
Then according to the previous scheme, we write four attributes in the controller;
Reboot the Startup class,
Page Input: HTTP://LOCALHOST:8888/HELLOWORLD/SHOWJDBC
The above kind if a lot of attributes to write a large string if multiple places to use every place to write so much undesirable
Below we introduce Configurationproperties configuration method
Create a new Mysqlproperties class to configure all properties
Execute prefix MSYQL
Plus @component as a component for easy injection elsewhere
Of course, this will prompt
Need to introduce dependency to Pom.xml
We can just click.
Change it in the Helloworldcontroller.
It is much more convenient to define mysqlproperties, in fact, to encapsulate all the attributes into another object, to find the corresponding configuration value in the configuration file by prefix, and establish a mapping relationship.
Results:
Springboot Project Property Configuration