This is a creation in Article, where the information may have evolved or changed.
1,docker variable
Define variables in Docker and use the Echo $Value to display directly on the command line,
This can be injected directly into the code using spring.
PHP has handy code to get the environment variables directly, but Java is a bit of a hassle.
Just use spring's value directly.
2, Code
For example, a spring user login action.
It uses Docker to configure a default admin login name and password.
In spring it can be written like this:
import org. Springframework. Beans. Factory. Annotation. Value;import org. Springframework. Web. Bind. Annotation. Requestmapping;import org. Springframework. Web. Bind. Annotation. Requestmethod;import org. Springframework. Web. Bind. Annotation. Requestparam;import org. Springframework. Web. Bind. Annotation. Restcontroller;@RestController @requestmapping ("/user") public class Useraction {@Value ("${default.admin.username}") Private String UserName;@Value ("${default.admin.password}") Private String Password;@RequestMapping (value ="/login", method = Requestmethod. POST) Public Resultjson Channelkey (@RequestParam (value ="UserName", DefaultValue ="") String UserName, @RequestParam (value ="Password", DefaultValue =""String password) {...}
3, simultaneous configuration under Spring
It is not possible to have such a code alone.
Spring is required to inject the configuration into it.
Spring configuration: Add such a line.
<context:propertyfile-encoding="UTF-8"/>
4, summary
And two previously written articles:
"Use junit&spring to modify the environment variables of the system to solve the Docker program test Problem"
http://blog.csdn.net/freewebsys/article/details/52781896
"Docker under development, modify environment variable start jetty"
http://blog.csdn.net/freewebsys/article/details/52782032
Explore how Java projects are migrated to Docker environment projects.
There are not many changes to the code. Docker deployment is easy and resource-saving is good. is the future trend.
The text of this text connection is: http://blog.csdn.net/freewebsys/article/details/51089323 not allowed to reprint without the Bo master.
Bo main address is: Http://blog.csdn.net/freewebsys