Browse Source

初始化网关服务器。

yangzhijie 6 years ago
commit
ff56d40997
7 changed files with 400 additions and 0 deletions
  1. 32 0
      .classpath
  2. 4 0
      .gitignore
  3. 81 0
      README.md
  4. 227 0
      pom.xml
  5. 25 0
      src/main/java/com/leanwo/gateway/GatewayApp.java
  6. 26 0
      src/main/resources/Application.yml
  7. 5 0
      src/main/resources/run.bat

+ 32 - 0
.classpath

@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" output="target/classes" path="src/main/java">
+		<attributes>
+			<attribute name="optional" value="true"/>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="src" output="target/test-classes" path="src/test/java">
+		<attributes>
+			<attribute name="optional" value="true"/>
+			<attribute name="maven.pomderived" value="true"/>
+			<attribute name="test" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
+		<attributes>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
+		<attributes>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
+		<attributes>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="output" path="target/classes"/>
+</classpath>

+ 4 - 0
.gitignore

@@ -0,0 +1,4 @@
+/.settings
+/.project
+/target
+*.class

+ 81 - 0
README.md

@@ -0,0 +1,81 @@
+# 文件服务器
+
+## 开发环境
+Git克隆源代码到本地
+```
+git clone http://www.leanwo.com:3000/ShangHaiLeanwo/FileServer.git
+```
+源代码导入到eclipse中。注意事项如下:
+1. 工作空间的编码格式设置成UTF-8。(Preferences-General-Workspace-Text file encoding-Other(UTF-8))
+2. 使用外部的maven(maven设置了国内镜像)
+*    2.1 Window-Preferences-Maven-Installations-Add-Installation home: Directory(Select apache maven install folder)-Finish
+*    2.2 Window-Preferences-Maven-User Settings-User Settings,(Browser)(Select apache maven install folder/config/settings.xml)-Update Settings
+
+## 默认配置
+* 修改端口号,打开resources/Application.yml,修改属性server.port可以修改启动的端口号。
+```
+server:
+  port: 85
+```
+* 修改Eureka服务器的地址,尽量不要修改该属性,该属性来源于服务管理器(ServerManagement)中的eureka.serviceUrl.defaultZone属性
+```
+#Eureka Server服务器地址.
+eureka:
+  client:
+    fetch-registry: true
+    register-with-eureka: true
+    serviceUrl:
+      defaultZone: http://localhost:88/eureka/
+```
+* 修改数据字典路径ProdogFileHome,修改resources/applicationContext.xml中的appConfig Bean的定义。
+```
+<bean id="appConfig" class="com.leanwo.file.util.AppConfig">
+	<!-- token -->
+	<property name="token" value="123456"></property>
+	<!-- Prodog File 文件夹的路径 -->
+	<property name="prodogFileHome" value="D:\LeanwoProgram_2019\OtherServer\FileServer\content"></property>
+</bean>
+```
+
+* 修改数据字典路径,修改resources/applicationContext-elfinder.xml中的fsServiceFactory Bean的定义,修改rootDir属性的定义。
+```
+<bean id="fsServiceFactory"
+		....
+					<!-- two volumes are mounted here -->
+					<map>
+						<entry key="A">
+							<bean class="cn.bluejoe.elfinder.localfs.LocalFsVolume">
+								<property name="name" value="数据字典" />
+								<property name="rootDir" value="D:\LeanwoProgram_2019\OtherServer\FileServer\content" />
+							</bean>
+						</entry>
+						<entry key="B">
+							<bean class="cn.bluejoe.elfinder.localfs.LocalFsVolume">
+								<property name="name" value="客户数据" />
+								<property name="rootDir" value="D:\LeanwoProgram_2019\OtherServer\FileServer\content\Files" />
+							</bean>
+						</entry>
+					</map>
+				....
+		</property>
+	</bean>
+```
+
+
+* 修改FTP配置,修改resources/applicationContext.xml中的ftpServerConfig Bean的定义。
+```
+<bean id="ftpServerConfig" class="com.leanwo.file.server.FtpServerConfig">
+  <!-- 是否启用FTP -->
+  <property name="enable" value="false"></property>
+  <!-- FTP通讯端口号 -->
+  <property name="port" value="21"></property>
+  <!-- 被动模式,FTP数据传输端口(必须大于1024) -->
+  <property name="passivePorts" value="1034-1040"></property>
+</bean>
+```
+属性名称 | 属性定义 |  备注  
+-|-|-
+enable | 是否开启FTP服务 | true:开启FTP服务,false:不开启FTP服务 |
+port | FTP端口号 | 默认21 |
+passivePorts | FTP被动模式端口号 | 被动模式,FTP数据传输端口,默认值(必须大于1024)1034-1040 |
+

+ 227 - 0
pom.xml

@@ -0,0 +1,227 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<groupId>com.leanwo.gateway</groupId>
+	<artifactId>GatewayServer</artifactId>
+	<version>0.0.1-SNAPSHOT</version>
+
+	<!--指定父级依赖 -->
+	<parent>
+		<groupId>org.springframework.boot</groupId>
+		<artifactId>spring-boot-starter-parent</artifactId>
+		<version>2.2.4.RELEASE</version>
+		<relativePath /> <!-- lookup parent from repository -->
+	</parent>
+
+	<properties>
+		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+		<h2.version>2.5.0-b60</h2.version>
+		<java.version>1.8</java.version>
+		<spring-cloud.version>Hoxton.RELEASE</spring-cloud.version>
+	</properties>
+
+	<dependencies>
+		<dependency>
+			<groupId>org.springframework.boot</groupId>
+			<artifactId>spring-boot-starter</artifactId>
+		</dependency>
+		
+		<dependency>
+			<groupId>org.springframework.cloud</groupId>
+			<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
+		</dependency>
+		
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
+        </dependency>
+        
+		<dependency>
+			<groupId>org.springframework.boot</groupId>
+			<artifactId>spring-boot-starter-test</artifactId>
+			<scope>test</scope>
+		</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>
+		<!-- jar包名 -->
+		<finalName>GatewayServer</finalName>
+		<!--默认源代码目录-->
+    	<sourceDirectory>src/main/java </sourceDirectory>
+		<!--默认测试源代码目录-->
+		<testSourceDirectory>src/test/java</testSourceDirectory>    
+		<!--默认资源目录-->    
+		<resources>
+			<resource>
+				<directory>src/main/resources</directory>
+			</resource>
+		</resources>
+
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<configuration>
+					<source>1.8</source>
+					<target>1.8</target>
+					<skip>true</skip>
+				</configuration>
+			</plugin>
+
+			<plugin>
+				<groupId>org.springframework.boot</groupId>
+				<artifactId>spring-boot-maven-plugin</artifactId>
+			</plugin>
+			
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-surefire-plugin</artifactId>
+				<version>2.20.1</version>
+				<configuration>
+					<skip>true</skip>
+				</configuration>
+			</plugin>
+
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-jar-plugin</artifactId>
+				<version>3.0.2</version>
+				<configuration>
+					<archive>
+						<manifest>
+							<addClasspath>true</addClasspath>
+							<classpathPrefix>lib/</classpathPrefix>
+							<mainClass>com.leanwo.file.server.FileServerApp</mainClass>
+						</manifest>
+					</archive>
+				</configuration>
+			</plugin>
+
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-dependency-plugin</artifactId>
+				<version>2.10</version>
+				<executions>
+					<execution>
+						<id>copy-dependencies</id>
+						<phase>package</phase>
+						<goals>
+							<goal>copy-dependencies</goal>
+						</goals>
+						<configuration>
+							<outputDirectory>${project.build.directory}/lib</outputDirectory>
+						</configuration>
+					</execution>
+				</executions>
+			</plugin>
+
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-resources-plugin</artifactId>
+				<version>3.0.2</version>
+				<executions>
+					<execution>
+						<id>copy-resources-config</id>
+						<phase>package</phase>
+						<goals>
+							<goal>copy-resources</goal>
+						</goals>
+						<configuration>
+							<encoding>UTF-8</encoding>
+							<outputDirectory>${project.build.directory}/FileServer/config
+							</outputDirectory>
+							<resources>
+								<resource>
+									<directory>config/</directory>
+									<excludes>
+										<exclude>*.bat</exclude>
+									</excludes>
+								</resource>
+							</resources>
+						</configuration>
+					</execution>
+
+
+					<execution>
+						<id>copy-resources-lib</id>
+						<phase>package</phase>
+						<goals>
+							<goal>copy-resources</goal>
+						</goals>
+						<configuration>
+							<encoding>UTF-8</encoding>
+							<outputDirectory>${project.build.directory}/FileServer/lib
+							</outputDirectory>
+							<resources>
+								<resource>
+									<directory>${project.build.directory}/lib/</directory>
+								</resource>
+							</resources>
+						</configuration>
+					</execution>
+
+					<execution>
+						<id>copy-resources-bat</id>
+						<phase>package</phase>
+						<goals>
+							<goal>copy-resources</goal>
+						</goals>
+						<configuration>
+							<encoding>UTF-8</encoding>
+							<outputDirectory>${project.build.directory}/FileServer/
+							</outputDirectory>
+							<resources>
+								<resource>
+									<directory>config/</directory>
+									<includes>
+										<include>*.bat</include>
+									</includes>
+								</resource>
+								<resource>
+									<directory>${project.build.directory}</directory>
+									<includes>
+										<include>FileServer*.jar</include>
+									</includes>
+								</resource>
+							</resources>
+						</configuration>
+					</execution>
+
+					<execution>
+						<id>copy-resources-content</id>
+						<phase>package</phase>
+						<goals>
+							<goal>copy-resources</goal>
+						</goals>
+						<configuration>
+							<encoding>UTF-8</encoding>
+							<outputDirectory>${project.build.directory}/FileServer/content
+							</outputDirectory>
+							<resources>
+								<resource>
+									<directory>content</directory>
+								</resource>
+							</resources>
+						</configuration>
+					</execution>
+				</executions>
+			</plugin>
+		</plugins>
+	</build>
+</project>

+ 25 - 0
src/main/java/com/leanwo/gateway/GatewayApp.java

@@ -0,0 +1,25 @@
+package com.leanwo.gateway;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
+import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
+
+
+@SpringBootApplication
+//@EnableDiscoveryClient//开启Eureka的客户端发现
+@EnableZuulProxy// 开启Zuul的网关功能
+public class GatewayApp {
+	
+	private static Logger logger = LoggerFactory.getLogger(GatewayApp.class);
+
+	public static void main(String[] args) throws Exception {
+		
+		SpringApplication.run(GatewayApp.class, args);
+
+		logger.info("网关服务器启动成功。");
+
+	}
+}

+ 26 - 0
src/main/resources/Application.yml

@@ -0,0 +1,26 @@
+#端口号
+server:
+  port: 80
+spring:
+  application:
+    # 应用名称,会在Eureka中作为服务的id标识(serviceId)
+    name: gateway-server
+    
+#Eureka Server服务器地址.
+eureka:
+  client:
+    fetch-registry: true
+    register-with-eureka: true
+    serviceUrl:
+      defaultZone: http://localhost:88/eureka/
+
+zuul:
+  #  隐藏所有微服务名称(即使用微服务名称无法访问到服务)
+  ignored-services: "*"
+  #  服务前缀名,想要访问项目之前要加上此路径
+  # prefix: /file-server
+  routes:
+    #只要访问以/editor/开头的多层目录都可以路由到服务名为file-server的服务上.
+    file-server:
+      serviceId: file-server
+      path: /**

+ 5 - 0
src/main/resources/run.bat

@@ -0,0 +1,5 @@
+title File Server
+set current_path="%cd%"
+cd %current_path%
+java -jar %current_path%\FileServer-0.0.1-SNAPSHOT.jar
+pause