Bladeren bron

发布成war

吴洪双 6 jaren geleden
bovenliggende
commit
f5202459b9

+ 20 - 55
pom.xml

@@ -7,7 +7,7 @@
 	<groupId>com.shawn</groupId>
 	<artifactId>ShenzeeServer</artifactId>
 	<version>0.0.1</version>
-	<packaging>jar</packaging>
+	<packaging>war</packaging>
 
 	<name>ShenzeeServer</name>
 	<description>spring discover server</description>
@@ -30,12 +30,25 @@
 	<dependencies>
 		<dependency>
 			<groupId>org.springframework.boot</groupId>
-			<artifactId>spring-boot-starter-jdbc</artifactId>
+			<artifactId>spring-boot-starter</artifactId>
 		</dependency>
 		<dependency>
 			<groupId>org.springframework.boot</groupId>
 			<artifactId>spring-boot-starter-web</artifactId>
+			<exclusions>
+				<exclusion>
+					<groupId>org.springframework.boot</groupId>
+					<artifactId>spring-boot-starter-tomcat</artifactId>
+				</exclusion>
+			</exclusions>
 		</dependency>
+		<!--修改Tomcat依赖时态,本地开发依然可以调用内嵌tomcat-->
+		<dependency>
+			<groupId>org.springframework.boot</groupId>
+			<artifactId>spring-boot-starter-tomcat</artifactId>
+			<scope>provided</scope>
+		</dependency>
+
 		<dependency>
 			<groupId>org.mybatis.spring.boot</groupId>
 			<artifactId>mybatis-spring-boot-starter</artifactId>
@@ -80,35 +93,6 @@
 			<version>1.2.58</version>
 		</dependency>
 
-		<!-- elasticsearch -->
-		<dependency>
-			<groupId>org.elasticsearch</groupId>
-			<artifactId>elasticsearch</artifactId>
-			<version>5.5.0</version>
-		</dependency>
-		<dependency>
-			<groupId>org.elasticsearch.client</groupId>
-			<artifactId>x-pack-transport</artifactId>
-			<version>5.5.2</version>
-		</dependency>
-
-		<dependency>
-			<groupId>org.elasticsearch.client</groupId>
-			<artifactId>transport</artifactId>
-			<version>5.5.2</version>
-		</dependency>
-
-		<dependency>
-			<groupId>org.elasticsearch.plugin</groupId>
-			<artifactId>x-pack-api</artifactId>
-			<version>5.5.2</version>
-		</dependency>
-		<dependency>
-			<groupId>org.elasticsearch.plugin</groupId>
-			<artifactId>transport-netty4-client</artifactId>
-			<version>5.5.2</version>
-		</dependency>
-
 		<!-- swagger2 -->
 		<dependency>
 			<groupId>io.springfox</groupId>
@@ -122,39 +106,20 @@
 		</dependency>
 	</dependencies>
 	
-	<dependencyManagement>
-		<dependencies>
-			<dependency>
-				<groupId>org.springframework.cloud</groupId>
-				<artifactId>spring-cloud-dependencies</artifactId>
-				<version>${spring-cloud.version}</version>
-				<type>pom</type>
-				<scope>import</scope>
-			</dependency>
-		</dependencies>
-	</dependencyManagement>
-
 	<build>
+		<finalName>ShenzeeServer</finalName>
 		<plugins>
+			<!-- Package the project as an executable jar -->
 			<plugin>
 				<groupId>org.springframework.boot</groupId>
 				<artifactId>spring-boot-maven-plugin</artifactId>
+				<!-- Set the character encoding for the JVM -->
 				<configuration>
-					<layout>ZIP</layout>
+					<jvmArguments>-Dfile.encoding=UTF-8</jvmArguments>
 				</configuration>
 			</plugin>
 		</plugins>
 	</build>
-	
-	<repositories>
-		<repository>
-			<id>spring-milestones</id>
-			<name>Spring Milestones</name>
-			<url>https://repo.spring.io/milestone</url>
-			<snapshots>
-				<enabled>false</enabled>
-			</snapshots>
-		</repository>
-	</repositories>
+
 
 </project>

+ 8 - 1
src/main/java/com/shawn/Application.java

@@ -3,10 +3,17 @@ package com.shawn;
 import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.builder.SpringApplicationBuilder;
+import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
 
 @SpringBootApplication //包含了@EnableAutoConfiguration
 @MapperScan("com.shawn.repository")
-public class Application {
+public class Application extends SpringBootServletInitializer {
+
+	@Override
+	protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
+		return builder.sources(Application.class);
+	}
 
 	public static void main(String[] args) {
 		SpringApplication.run(Application.class, args);

+ 2 - 1
src/main/java/com/shawn/web/exception/ExceptionHandlerControllerAdvice.java

@@ -1,6 +1,5 @@
 package com.shawn.web.exception;
 
-import org.apache.catalina.servlet4preview.http.HttpServletRequest;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.ControllerAdvice;
@@ -12,6 +11,8 @@ import com.shawn.model.dto.ResultMessage;
 
 import lombok.extern.slf4j.Slf4j;
 
+import javax.servlet.http.HttpServletRequest;
+
 /**
  * @author 吴洪双
  */

+ 2 - 1
src/main/resources/application.properties

@@ -10,7 +10,8 @@ logging.level.com.shawn=DEBUG
 # File output
 logging.file.max-size=100MB
 logging.file.max-history=200
-logging.file=/Users/wuhs/workplace/mylogs/${spring.application.name}/${spring.application.name}.log
+#logging.file=/Users/wuhs/workplace/mylogs/${spring.application.name}/${spring.application.name}.log
+logging.file=../logs/${spring.application.name}/${spring.application.name}.log
 
 mybatis.mapper-locations=classpath:com/shawn/repository/mybatis/*Mapper.xml
 mybatis.type-aliases-package=com.shawn.model