In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Taking development testing as an example, this paper introduces the switching between test environment and development environment by using profile under tomcat deployment application and maven deployment application.
I. tomcat deployment applications
1. Data source configuration
Dev.properties path: / src/main/resrouces
Jdbc.database=MYSQLjdbc.driver=com.mysql.jdbc.Driverjdbc.url=jdbc:mysql://mysql:3306/develop?useUnicode=true&characterEncoding=utf-8jdbc.schema=developjdbc.username=rootjdbc.password=12qw4ds
Test.properties path: / src/main/resrouces
Jdbc.database=MYSQLjdbc.driver=com.mysql.jdbc.Driverjdbc.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8jdbc.schema=testjdbc.username=rootjdbc.password=123456
ApplicationContext-detabase.xml path: src/main/resources/spring
2 、 springmvc.xml webapp/WEB-INF
You can separate the data source configuration of a development and production environment by defining a profile
2. Define the default profile in web.xml:
The default profile means that the content defined in the default profile will be used when no profile is activated. You can usually define the global servlet context parameter spring.profiles.default implementation in web.xml.
Spring.profiles.default development
4. Activate profile
Spring provides us with a large number of methods to activate profile, which can be activated by code, or through system environment variables, JVM parameters, servlet context parameters to determine spring.profiles.active parameters to activate profile, here we define JVM parameters. Taking tomcat as an example, we add the following JVM parameters to the startup script of tomcat
JAVA_OPTS= "- Dspring.profiles.active=development-server-XX:PermSize=256M-XX:MaxPermSize=512M-Xms1024M-Xmx1024M-Xss512k-XX:LargePageSizeInBytes=128m-XX:MaxTenuringThreshold=15-XX:+AggressiveOpts-XX:+UseBiasedLocking-XX:+DisableExplicitGC-XX:+UseConcMarkSweepGC-XX:+UseParNewGC-XX:+CMSParallelRemarkEnabled-XX:+UseFastAccessorMethods-XX:+UseCMSInitiatingOccupancyOnly-XX:+HeapDumpOnOutOfMemoryError-XX:HeapDumpPath=$CATALINA_BASE/heap.dump.bin-Djava.awt.headless=true"
If it is not defined, the default profile we specified will be used
II. Maven deployment applications
1. Configuration file
The dev.properties path is / src/main/resources/filter
Master.jdbc.driverClass = com.mysql.jdbc.Drivermaster.jdbc.url = jdbc:mysql://mysql-dev:3306/devmaster.jdbc.user = rootmaster.jdbc.password = Aa12345678
The test.properties path is / src/main/resources/filter
Master.jdbc.driverClass = com.mysql.jdbc.Drivermaster.jdbc.url = jdbc:mysql://mysql-test:3306/testmaster.jdbc.user = rootmaster.jdbc.password = root
Config.properties path: / src/main/resource/META-INF
Master.jdbc.driverClass = ${master.jdbc.driverClass} master.jdbc.url = ${master.jdbc.url} master.jdbc.user = ${master.jdbc.user} master.jdbc.password = ${master.jdbc.password}
The spring-datasource.xml path is: / src/main/resources/spring
2 、 pom.xml
Dev true / profile/dev.properties dev Test / profile/test.properties test pro / profile/pro.properties pro. Src/main/resources/filter/$ {env} .properties src/main/resources template**/** false
The default activation can be configured as follows
True
Filters: used to define the location of the specified filter properties file, such as the filter element assignment filters/filter1.properties, then the name=value pair can be defined in this file, and the value of this name=value pair can be referenced by ${name} in the project pom. The default filter directory is ${basedir} / src/main/filters/.
Resources: describes the location of resources in the project
3 、 spring-bean.xml
Classpath:/META-INF/config.properties
4 、 web.xml
ContextConfigLocation classpath:spring/spring-bean.xml
5. Packing
Maven clean install-Pdev
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.