模块化拆分

This commit is contained in:
禾几海
2021-10-01 15:43:54 +08:00
parent 7e700b6499
commit ef2f98e45f
25 changed files with 132 additions and 44 deletions

View File

@@ -2,8 +2,15 @@ package cn.celess.common;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
@SpringBootApplication
@SpringBootApplication(
scanBasePackageClasses = {
CommonApplication.class
}
)
@ComponentScan(excludeFilters = {@ComponentScan.Filter(type = FilterType.REGEX, pattern = "cn.celess.common.test.BaseRedisTest")})
public class CommonApplication {
public static void main(String[] args) {
SpringApplication.run(CommonApplication.class, args);

View File

@@ -1,5 +1,7 @@
package cn.celess.common.test;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import redis.embedded.RedisServer;
import javax.annotation.PostConstruct;
@@ -10,7 +12,9 @@ import java.io.IOException;
* @author : xiaohai
* @date : 2020/08/14 16:20
*/
public class RedisServerMock extends BaseTest {
@Configuration
@Slf4j
public class BaseRedisTest extends BaseTest {
private static RedisServer redisServer;
@PostConstruct
@@ -19,14 +23,19 @@ public class RedisServerMock extends BaseTest {
if (redisServer == null) {
redisServer = new RedisServer(6380);
redisServer.start();
log.info("start Redis success");
}
} catch (IOException e) {
log.error("start Redis failed");
e.printStackTrace();
}
}
@PreDestroy
@PreDestroy()
public static void stopRedis() {
if (redisServer.isActive()) redisServer.stop();
if (redisServer.isActive()) {
redisServer.stop();
log.info("stop Redis success");
}
}
}

View File

@@ -15,10 +15,14 @@ import java.io.IOException;
* @Desc:
*/
public class HttpUtil {
/**
* FIXME
* 获取http请求的响应
*
* @param url url链接
* @return 请求的响应
*/
public static String get(String urlStr) {
public static String getHttpResponse(String url) {
try (final WebClient webClient = new WebClient(BrowserVersion.CHROME)) {
webClient.getOptions().setCssEnabled(false);
webClient.getOptions().setJavaScriptEnabled(false);
@@ -27,18 +31,18 @@ public class HttpUtil {
webClient.getOptions().setDownloadImages(false);
webClient.getOptions().setActiveXNative(false);
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
Page clientPage = webClient.getPage(urlStr);
if (clientPage.isHtmlPage()) {
return clientPage.toString();
}
return null;
Page clientPage = webClient.getPage(url);
return clientPage.getWebResponse().getContentAsString();
} catch (IOException e) {
return null;
}
}
/**
* FIXME
* 获取渲染后的网页数据
*
* @param url url链接
* @return 经js渲染后的网页源代码
*/
public static String getAfterRendering(String url) {
try (final WebClient webClient = new WebClient(BrowserVersion.BEST_SUPPORTED)) {