First, the core dependence
The dependency of WebApp is broadly divided into three parts: Basic Spring component dependencies, log and test components, Web Component dependencies, and so on. The approximate:
<dependencies> <!--1.base Spring Dependency---<dependency> <groupid>org.springframew Ork</groupid> <artifactId>spring-core</artifactId> <VERSION>${VERSION.SPRINGFRAMEWORK}&L t;/version> </dependency> <dependency> <groupId>org.springframework</groupId> & Lt;artifactid>spring-beans</artifactid> <version>${version.springframework}</version> </ dependency> <dependency> <groupId>org.springframework</groupId> <artifactid>spring -context</artifactid> <version>${version.springframework}</version> </dependency> <d Ependency> <groupId>org.springframework</groupId> <artifactid>spring-context-support</ar Tifactid> <version>${version.springframework}</version> </dependency> <!--2.base L Ogger and test dependency-<dependency> <groupId>org.apache.logging.log4j</groupId> <artifactid>log4j-cor e</artifactid> <version>${version.log4j}</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>${versi on.slf4j}</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>${version.slf4j}</version> </ dependency> <dependency> <groupId>junit</groupId> <artifactid>junit</artifactid > <version>${version.junit}</version> <scope>test</scope> </dependency> & Lt;dependency> <groupId>org.springframework</groupId> <artifactid>spring-test</artifacti D> <version>${versioN.springframework}</version> <scope>test</scope> </dependency> <!--3.base Web D Ependency-<dependency> <groupId>org.springframework</groupId> <artifactid>spri ng-web</artifactid> <version>${version.springframework}</version> </dependency> <DEP Endency> <groupId>org.springframework</groupId> <artifactid>spring-webmvc</artifactid> ; <version>${version.springframework}</version> </dependency> <dependency> <groupid> ;javax.servlet</groupid> <artifactId>javax.servlet-api</artifactId> <VERSION>${VERSION.J avax.servlet.api}</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>javax.servlet.jsp-api</artifactId> & Lt;version>${version.javax.servlet.jsp.api}</version> <scope>provided</scope> </dependency> <depen dency> <groupId>com.tutianer</groupId> <artifactId>common</artifactId> <versi On>${version.tutianer.common}</version> </dependency> </dependencies>
View Code
Second, the project construction configuration
A common configuration item for project building is to set up JDK versions and resource filtering. As follows:
<build> <pluginManagement> <plugins> <plugin> <groupid>org.apache.ma Ven.plugins</groupid> <artifactId>maven-compiler-plugin</artifactId> <configuration > <source>1.8</source> <target>1.8</target> </CONFIGURATION&G T </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifa Ctid>maven-resources-plugin</artifactid> <configuration> <resources> <resource> <directory>${project.basedir}/src/main/resources</directory> & Lt;filtering>true</filtering> </resource> </resources> </configuration> < ;/plugin> <plugin> <groupId>org.eclipse.jetty</groupId> <artifactid>je Tty-maven-plugin</artifactid> <version>${version.jetty}</version> <configuration> ; View CodeWhere Finalename represents WebApp's packaged name, as the default Web project, set to ROOT can be used directly in Tomcat.
Third, attribute configuration
<profiles> <profile> <id>dev</id> <activation> <ACTIVEB Ydefault>true</activeByDefault> </activation> <properties> <config.logger.level>in Fo</config.logger.level> <config.redis.server>127.0.0.1</config.redis.server> < Config.redis.port>6379</config.redis.port> <config.redis.prefixkey>local_</config.redis.prefi Xkey> <config.db.driverClassName>com.mysql.jdbc.Driver</config.db.driverClassName> &L T;config.db.url>jdbc:mysql://localhost:3306/dbname?characterencoding=utf8&useunicode=true&usessl=false</ Config.db.url><config.db.username>root</config.db.username> <config.db.password>123456</config.db.passwo Rd> <config.domain>http://localhost:8002</config.domain></properties> </profile> <profile> <id>prod</id> <properties& Gt <config.logger.level>INFO</config.logger.level> <config.redis.server>127.0.0.1</config.red Is.server> <config.redis.port>6382</config.redis.port> <config.redis.prefixKey> Prod_</config.redis.prefixkey> <config.db.driverclassname>com.mysql.jdbc.driver</config.db.drive Rclassname> <config.db.url>jdbc:mysql://localhost:3306/dbname?characterencoding=utf8&useunicode=true&usessl=false</ Config.db.url><config.db.username>username</config.db.username> <CONFIG.DB.PASSWORD>PWD</CONFIG.DB.PASSW Ord> <config.domain>http://domain</config.domain></properties> </profile> </profiles>
View CodeIn general development, a common problem is to switch back and forth in several environments, such as local development, testing, production, and so on, and Maven's property configuration is a good solution. When the Maven-resources-plugin plug-in is used in a project build configuration, the values configured in the properties are automatically replaced in the resource directory specified by Maven-resources-plugin when testing or packaging.
It is important to note that the database configuration is escaped with &, and that the item is configured directly in the XML file and does not need to be escaped.
The default activation is the configuration section where Activebydefault is located, and activating other configurations when packaging or testing requires the parameter p to specify the active configuration item:-P PROD
Iv. Web Version Configuration
Since Maven's archvetype is slightly stale, the created WebApp will be set to version 2.3 and can be modified to 2.5 in the configuration file. The configuration file is a Org.eclipse.wst.common.project.facet.core.xml file in the Web project. Setting directory, which will
<installed facet= "Jst.web" version= "2.3"/>
Modified to:
<installed facet= "Jst.web" version= "2.5"/>
Five, the rest of the configuration
Other configuration information such as spring, Web. XML, etc.
Maven-built WebApp basic configuration