Skip to content

Commit 6ef689b

Browse files
committed
Java:新增 APIJSONDemo-Hadoop
1 parent 24ffd59 commit 6ef689b

File tree

8 files changed

+562
-0
lines changed

8 files changed

+562
-0
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,5 @@ APIJSON-Java-Server/APIJSONDemo-ClickHouse/.idea
2929
APIJSON-Java-Server/APIJSONDemo-Elasticsearch/target
3030
APIJSON-Java-Server/APIJSONDemo-ClickHouse/target
3131
APIJSON-Java-Server/APIJSONDemo-Elasticsearch/.idea
32+
APIJSON-Java-Server/APIJSONDemo-Hadoop/.idea
33+
APIJSON-Java-Server/APIJSONDemo-Hadoop/target

Diff for: APIJSON-Java-Server/APIJSONDemo-Hadoop/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# APIJSONDemo
2+
3+
APIJSON + SpringBoot 初级使用的最简单 Demo
4+
5+
### 运行
6+
7+
右键 DemoApplication > Run As > Java Application

Diff for: APIJSON-Java-Server/APIJSONDemo-Hadoop/pom.xml

+185
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>apijson.demo</groupId>
7+
<artifactId>apijson-demo</artifactId>
8+
<version>5.4.0</version>
9+
10+
<name>APIJSONDemo-Hadoop</name>
11+
<description>Demo project for testing APIJSON server based on SpringBoot</description>
12+
13+
<properties>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
16+
<java.version>1.8</java.version>
17+
</properties>
18+
19+
<dependencies>
20+
<!-- JDK 11+ 需要,否则启动报错 NoClassDefFoundError: javax/activation/UnsupportedDataTypeException -->
21+
<dependency>
22+
<groupId>javax.activation</groupId>
23+
<artifactId>activation</artifactId>
24+
<version>1.1.1</version>
25+
</dependency>
26+
27+
<!-- 需要的 APIJSON 相关依赖 -->
28+
<dependency>
29+
<groupId>com.github.Tencent</groupId>
30+
<artifactId>APIJSON</artifactId>
31+
<version>5.4.0</version>
32+
</dependency>
33+
<dependency>
34+
<groupId>com.github.APIJSON</groupId>
35+
<artifactId>apijson-framework</artifactId>
36+
<version>5.3.0</version>
37+
<exclusions>
38+
<exclusion>
39+
<groupId>com.github.Tecent</groupId>
40+
<artifactId>APIJSON</artifactId>
41+
</exclusion>
42+
</exclusions>
43+
</dependency>
44+
45+
<!-- 需要用的数据库 JDBC 驱动 -->
46+
<dependency>
47+
<groupId>org.apache.hadoop</groupId>
48+
<artifactId>hadoop-common</artifactId>
49+
<version>2.6.5</version>
50+
<exclusions>
51+
<exclusion>
52+
<artifactId>servlet-api</artifactId>
53+
<groupId>javax.servlet</groupId>
54+
</exclusion>
55+
<exclusion>
56+
<groupId>org.apache.logging.log4j</groupId>
57+
<artifactId>log4j-slf4j-impl</artifactId>
58+
</exclusion>
59+
<exclusion>
60+
<groupId>org.slf4j</groupId>
61+
<artifactId>slf4j-log4j12</artifactId>
62+
</exclusion>
63+
<exclusion>
64+
<groupId>org.apache.log4j</groupId>
65+
<artifactId>org.apache.hive.org.apache.log4j</artifactId>
66+
</exclusion>
67+
<exclusion>
68+
<groupId>log4j</groupId>
69+
<artifactId>log4j</artifactId>
70+
</exclusion>
71+
</exclusions>
72+
</dependency>
73+
<dependency>
74+
<groupId>org.apache.hive</groupId>
75+
<artifactId>hive-jdbc</artifactId>
76+
<version>1.1.0</version>
77+
<!-- <scope>provided</scope>-->
78+
<exclusions>
79+
<exclusion>
80+
<groupId>org.eclipse.jetty.aggregate</groupId>
81+
<artifactId>*</artifactId>
82+
</exclusion>
83+
<exclusion>
84+
<groupId>org.apache.tomcat.embed</groupId>
85+
<artifactId>*</artifactId>
86+
</exclusion>
87+
<exclusion>
88+
<groupId>javax.servlet</groupId>
89+
<artifactId>servlet-api</artifactId>
90+
</exclusion>
91+
<exclusion>
92+
<artifactId>jdk.tools</artifactId>
93+
<groupId>*</groupId>
94+
</exclusion>
95+
<exclusion>
96+
<groupId>org.apache.logging.log4j</groupId>
97+
<artifactId>log4j-slf4j-impl</artifactId>
98+
</exclusion>
99+
<exclusion>
100+
<groupId>org.slf4j</groupId>
101+
<artifactId>slf4j-log4j12</artifactId>
102+
</exclusion>
103+
<exclusion>
104+
<groupId>org.apache.log4j</groupId>
105+
<artifactId>org.apache.hive.org.apache.log4j</artifactId>
106+
</exclusion>
107+
<exclusion>
108+
<groupId>log4j</groupId>
109+
<artifactId>log4j</artifactId>
110+
</exclusion>
111+
<exclusion>
112+
<groupId>com.google.code.gson</groupId>
113+
<artifactId>*</artifactId>
114+
</exclusion>
115+
</exclusions>
116+
</dependency>
117+
<dependency>
118+
<groupId>com.google.code.gson</groupId>
119+
<artifactId>gson</artifactId>
120+
<version>2.8.5</version>
121+
<scope>provided</scope>
122+
</dependency>
123+
<!-- Oracle, SQLServer 等其它数据库的 JDBC 驱动,可以在这里加上 Maven 依赖或 libs 目录放 Jar 包并依赖 -->
124+
125+
<!-- 需要用的 SpringBoot 框架,1.4.0 以上 -->
126+
<dependency>
127+
<groupId>org.springframework.boot</groupId>
128+
<artifactId>spring-boot-starter-web</artifactId>
129+
<version>2.0.1.RELEASE</version>
130+
</dependency>
131+
132+
</dependencies>
133+
134+
<build>
135+
<plugins>
136+
<plugin>
137+
<groupId>org.springframework.boot</groupId>
138+
<artifactId>spring-boot-maven-plugin</artifactId>
139+
<configuration>
140+
<fork>true</fork>
141+
<mainClass>apijson.demo.DemoApplication</mainClass>
142+
</configuration>
143+
<executions>
144+
<execution>
145+
<goals>
146+
<goal>repackage</goal>
147+
</goals>
148+
</execution>
149+
</executions>
150+
</plugin>
151+
<plugin>
152+
<groupId>org.apache.maven.plugins</groupId>
153+
<artifactId>maven-compiler-plugin</artifactId>
154+
<configuration>
155+
<source>1.8</source>
156+
<target>1.8</target>
157+
</configuration>
158+
</plugin>
159+
</plugins>
160+
</build>
161+
162+
<repositories>
163+
<!-- APIJSON 必须用到的托管平台 -->
164+
<repository>
165+
<id>jitpack.io</id>
166+
<url>https://jitpack.io</url>
167+
<snapshots>
168+
<enabled>true</enabled>
169+
</snapshots>
170+
</repository>
171+
172+
<repository>
173+
<id>spring-snapshots</id>
174+
<url>https://repo.spring.io/snapshot</url>
175+
<snapshots>
176+
<enabled>true</enabled>
177+
</snapshots>
178+
</repository>
179+
<repository>
180+
<id>spring-milestones</id>
181+
<url>https://repo.spring.io/milestone</url>
182+
</repository>
183+
</repositories>
184+
185+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon/APIJSON)
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.*/
14+
15+
package apijson.demo;
16+
17+
import org.springframework.boot.SpringApplication;
18+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
19+
import org.springframework.boot.autoconfigure.SpringBootApplication;
20+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
21+
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
22+
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
23+
import org.springframework.context.annotation.Bean;
24+
import org.springframework.context.annotation.Configuration;
25+
import org.springframework.web.servlet.config.annotation.CorsRegistry;
26+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
27+
28+
import apijson.Log;
29+
import apijson.framework.APIJSONApplication;
30+
import apijson.framework.APIJSONCreator;
31+
import apijson.orm.SQLConfig;
32+
import apijson.orm.SQLExecutor;
33+
34+
35+
/**
36+
* Demo SpringBoot Application 主应用程序启动类
37+
* 右键这个类 > Run As > Java Application
38+
* 具体见 SpringBoot 文档
39+
* https://www.springcloud.cc/spring-boot.html#using-boot-locating-the-main-class
40+
*
41+
* @author Lemon
42+
*/
43+
@Configuration
44+
@SpringBootApplication
45+
@EnableAutoConfiguration
46+
@EnableConfigurationProperties
47+
public class DemoApplication implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> {
48+
public static final String TAG = "DemoApplication";
49+
50+
public static void main(String[] args) throws Exception {
51+
SpringApplication.run(DemoApplication.class, args);
52+
53+
Log.DEBUG = true;
54+
APIJSONApplication.init(false); // 4.4.0 以上需要这句来保证以上 static 代码块中给 DEFAULT_APIJSON_CREATOR 赋值会生效
55+
}
56+
57+
// SpringBoot 2.x 自定义端口方式
58+
@Override
59+
public void customize(ConfigurableServletWebServerFactory server) {
60+
server.setPort(8080);
61+
}
62+
63+
// 支持 APIAuto 中 JavaScript 代码跨域请求
64+
@Bean
65+
public WebMvcConfigurer corsConfigurer() {
66+
return new WebMvcConfigurer() {
67+
@Override
68+
public void addCorsMappings(CorsRegistry registry) {
69+
registry.addMapping("/**")
70+
.allowedOrigins("*") //.allowedOriginPatterns("*")
71+
.allowedMethods("*")
72+
.allowCredentials(true)
73+
.maxAge(3600);
74+
}
75+
};
76+
}
77+
78+
static {
79+
// 使用本项目的自定义处理类
80+
APIJSONApplication.DEFAULT_APIJSON_CREATOR = new APIJSONCreator<Long>() {
81+
@Override
82+
public SQLConfig createSQLConfig() {
83+
return new DemoSQLConfig();
84+
}
85+
86+
@Override
87+
public SQLExecutor createSQLExecutor() {
88+
return new DemoSQLExecutor();
89+
}
90+
};
91+
92+
try { //加载驱动程序
93+
Log.d(TAG, "尝试加载 Hive 驱动 <<<<<<<<<<<<<<<<<<<<< ");
94+
Class.forName("org.apache.hive.jdbc.HiveDriver");
95+
Log.d(TAG, "成功加载 Hive 驱动!>>>>>>>>>>>>>>>>>>>>> ");
96+
}
97+
catch (ClassNotFoundException e) {
98+
e.printStackTrace();
99+
Log.e(TAG, "加载 Hive 驱动失败,请检查 pom.xml 中 hive-jdbc 版本是否存在以及可用 !!!");
100+
}
101+
102+
}
103+
104+
}

0 commit comments

Comments
 (0)