1. 网络爬虫
网络爬虫(英语:web crawler),也叫网络蜘蛛(spider),是一种用来自动浏览万维网的网络机器人。其目的一般为编纂网络索引。简单来说,就是获取请求的页面源码,再通过正则表达式获取自己需要的内容。 实现的时候大致分为以下几个步骤:
(1)爬取网页源码
(2)利用正则截取自己需要的内容(我这里截取问题,以及下面的回答)
2.爬取网页源码
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
public class Spider {
/**
* @auther: Ragty
* @describe: 爬虫爬取网页源码
* @param: [url]
* @return: java.lang.String
* @date: 2019/1/23
*/
public static String getSource (String url) {
BufferedReader reader = null;
String result = "";
try {
URL realurl = new URL(url);
URLConnection conn = realurl.openConnection(); //连接外部url
reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line = "";
while ( (line = reader.readLine()) != null ) {
result += line;
}
if (reader != null) {
reader.close();
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
}
3.抓取规则及实体类
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import JavaSpider.spider.Spider;
public class Imooc {
public String question;
public String quesUrl;
public String quesDescription;
public Map<String,String> answers;
public String nextUrl;
/**
* @auther: Ragty
* @describe: 爬取慕课问答界面的问题及回答
* @param: [url]
* @return:
* @date: 2019/1/23
*/
public Imooc(String url) {
question="";
quesUrl=url;
quesDescription="";
answers = new HashMap<String,String>();
nextUrl="";
//获取单个问题页面源码
String codeSource = Spider.getSource(url);
//正则获取question
Pattern pattern=Pattern.compile("js-qa-wenda-title.+?>(.+?)</h1>");
Matcher matcher=pattern.matcher(codeSource);
if(matcher.find()){
question = matcher.group(1);
}
//正则表达式获取问题描述
pattern=Pattern.compile("js-qa-wenda.+?rich-text\">(.+?)</div>");
matcher=pattern.matcher(codeSource);
if(matcher.find()){
quesDescription = matcher.group(1).replace("<p>", "").replace("</p>", "");
}
//正则表达式获取答案列表
pattern=Pattern.compile("nickname.+?>(.+?)</a>.+?answer-desc rich-text aimgPreview.+?>(.+?)</div>");
matcher=pattern.matcher(codeSource);
while(matcher.find()){
String answer = matcher.group(2).replace("<p>", "");
answer = answer.replace("</p>", "");
answer = answer.replace("<br />", "");
String name = matcher.group(1);
answers.put(name.trim(), answer.trim());
}
//正则表达式获取下一个url 爬取获取相关问题的url
pattern=Pattern.compile("class=\"r relwenda\".+?href=\"(.+?)\".+?</a>");//获取回答者name
matcher=pattern.matcher(codeSource);
while(matcher.find()){
nextUrl="http://www.imooc.com"+matcher.group(1);
//只取第一个推荐
if(!nextUrl.equals(quesUrl)){
break;
}
}
}
@Override
public String toString() {
return "问题为:"+ question +"\n问题地址为:"+quesUrl+
"\n问题的表述为:"+quesDescription+"\n"
+ "回答的内容为:"+answers+"\n指向下一个链接地址为:"+nextUrl+"\n";
}
}
3.抓取测试类
package JavaSpider.main;
import JavaSpider.bean.Imooc;
public class Main {
public static void main(String[] args) {
String url = "http://www.imooc.com/wenda/detail/351144";
Imooc imooc;
for(int i=0; i<5;i++){
imooc = new Imooc(url);
url = imooc.nextUrl;
System.out.println(imooc);
}
}
}
4.测试网站原样
测试网址:http://www.imooc.com/wenda/detail/351144
5. 测试效果
问题为:为啥要做程序员,初心是什么?
问题地址为:http://www.imooc.com/wenda/detail/351144
问题的表述为: 如题<br />
回答的内容为:{慕粉1043575294=一位大牛曾经说过:“我以前原本以为计算机是一个很好的工具,但我真正了解它我才发现或许它也可以像我们一样拥有生命!我想让她活过来。”(我没那么高的逼格,当初接触这个目的只是为了赚点外快。希望可以帮助迷茫的你), 浩哥辣么帅=专业就是这个,感觉挣得也多,好好学,不会太差,然后就一直做这个了。, Ea_=<pre class="brush:js;toolbar:false">console.log("%c 为了活着","color:red")</pre>, 慕尼黑1381709=return "一失足成千古恨", qq_lol_9=为了养的起我的女人,让她过的更好!, 小熊熊HELLO=<strong>听说工资高</strong>, 不可忍=想跟被人一样装逼, Lani_Carol=<pre class="brush:java;toolbar:false">System.out.println("可能只是因为一时的突发奇想,选择了这条不归路。所以硬着头皮也要走下去!");</pre>, 望远=<pre class="brush:bash;toolbar:false">echo "一切不以赚钱为目的的工作都是在浪费生命!!"</pre>, 秋名山车神=因为想学技术, 程序蒜=<pre class="brush:php;toolbar:false;">for (i=1; i<=999999999999999999999999999999999999999; i++) { echo "被逼的!";}</pre>, Caballarii=赚钱,装什么高大上, 慕村1106498=<pre class="brush:php;toolbar:false"><?php echo "I Love PHP";?></pre>, 萧俊介=<pre class="brush:php;toolbar:false">echo "为了找个合理的理由穿女装!"</pre>, 江户川秋风=为了毛爷爷, 天使之翼死神之镰=心之所向, 慕粉1922268251=<p dir="ltr">听说能坐办公室。。。, qq_你微笑时好美_04175474=<pre class="brush:java;toolbar:false">System.out.println("感兴趣");</pre>, 加加摩尔=初心还能有啥,小时候游戏玩多了,天天想摸着电脑,长大又觉得黑很牛逼,然后学了个编程语言天天混迹在温饱线上~, 叫我娜姐=<pre class="brush:js;toolbar:false">alert("听说是可以坐着上班的,还可以天天玩电脑。");</pre>}
指向下一个链接地址为:http://www.imooc.com/wenda/detail/493069
问题为:springboot2.1 引入spring-boot-starter-web时启动报错
问题地址为:http://www.imooc.com/wenda/detail/493069
问题的表述为: idea生成的springboot项目,当pom文件引入spring-boot-starter-web时 启动报错<pre class="brush:java;toolbar:false">java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [NonLoginAuthenticator[StandardEngine[Tomcat].StandardHost[localhost].TomcatEmbeddedContext[]]] at java.util.concurrent.FutureTask.report(FutureTask.java:122) [na:1.8.0_191] at java.util.concurrent.FutureTask.get(FutureTask.java:192) [na:1.8.0_191] at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:914) [tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:831) [tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1382) [tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1372) [tomcat-embed-core-9.0.14.jar:9.0.14] at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266) [na:1.8.0_191] at java.util.concurrent.FutureTask.run(FutureTask.java) [na:1.8.0_191] at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) [tomcat-embed-core-9.0.14.jar:9.0.14] at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134) [na:1.8.0_191] at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:907) [tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262) [tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.core.StandardService.startInternal(StandardService.java:423) [tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:933) [tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.startup.Tomcat.start(Tomcat.java:398) [tomcat-embed-core-9.0.14.jar:9.0.14] at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:106) [spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE] at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:86) [spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE] at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:415) [spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE] at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:174) [spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:181) [spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:154) [spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:540) [spring-context-5.1.4.RELEASE.jar:5.1.4.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) [spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE] at com.example.demo.DemoApplication.main(DemoApplication.java:10) [classes/:na]Caused by: org.apache.catalina.LifecycleException: Failed to start component [NonLoginAuthenticator[StandardEngine[Tomcat].StandardHost[localhost].TomcatEmbeddedContext[]]] at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:441) [tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:198) [tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.core.StandardPipeline.startInternal(StandardPipeline.java:181) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5041) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1382) [tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1372) [tomcat-embed-core-9.0.14.jar:9.0.14] at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266) [na:1.8.0_191] at java.util.concurrent.FutureTask.run(FutureTask.java) [na:1.8.0_191] at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) [tomcat-embed-core-9.0.14.jar:9.0.14] at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134) [na:1.8.0_191] at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:907) [tomcat-embed-core-9.0.14.jar:9.0.14] ... 30 common frames omittedCaused by: java.lang.NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String; at org.apache.catalina.authenticator.AuthenticatorBase.startInternal(AuthenticatorBase.java:1178) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core-9.0.14.jar:9.0.14] ... 41 common frames omitted2019-01-21 22:19:30.303 ERROR 30556 --- [ main] org.apache.catalina.core.ContainerBase : A child container failed during startjava.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: A child container failed during start at java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[na:1.8.0_191] at java.util.concurrent.FutureTask.get(FutureTask.java:192) ~[na:1.8.0_191] at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:914) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262) [tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.core.StandardService.startInternal(StandardService.java:423) [tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:933) [tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.startup.Tomcat.start(Tomcat.java:398) [tomcat-embed-core-9.0.14.jar:9.0.14] at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:106) [spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE] at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:86) [spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE] at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:415) [spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE] at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:174) [spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:181) [spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:154) [spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:540) [spring-context-5.1.4.RELEASE.jar:5.1.4.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) [spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE] at com.example.demo.DemoApplication.main(DemoApplication.java:10) [classes/:na]Caused by: org.apache.catalina.LifecycleException: A child container failed during start at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:926) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:831) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1382) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1372) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266) ~[na:1.8.0_191] at java.util.concurrent.FutureTask.run(FutureTask.java) ~[na:1.8.0_191] at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134) ~[na:1.8.0_191] at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:907) ~[tomcat-embed-core-9.0.14.jar:9.0.14] ... 21 common frames omittedCaused by: java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [NonLoginAuthenticator[StandardEngine[Tomcat].StandardHost[localhost].TomcatEmbeddedContext[]]] at java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[na:1.8.0_191] at java.util.concurrent.FutureTask.get(FutureTask.java:192) ~[na:1.8.0_191] at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:914) ~[tomcat-embed-core-9.0.14.jar:9.0.14] ... 30 common frames omittedCaused by: org.apache.catalina.LifecycleException: Failed to start component [NonLoginAuthenticator[StandardEngine[Tomcat].StandardHost[localhost].TomcatEmbeddedContext[]]] at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:441) [tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:198) [tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.core.StandardPipeline.startInternal(StandardPipeline.java:181) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5041) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1382) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1372) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266) ~[na:1.8.0_191] at java.util.concurrent.FutureTask.run(FutureTask.java) ~[na:1.8.0_191] at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134) ~[na:1.8.0_191] at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:907) ~[tomcat-embed-core-9.0.14.jar:9.0.14] ... 30 common frames omittedCaused by: java.lang.NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String; at org.apache.catalina.authenticator.AuthenticatorBase.startInternal(AuthenticatorBase.java:1178) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core-9.0.14.jar:9.0.14] ... 41 common frames omittedDisconnected from the target VM, address: '127.0.0.1:57321', transport: 'socket'2019-01-21 22:19:30.321 INFO 30556 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]2019-01-21 22:19:30.322 WARN 30556 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat2019-01-21 22:19:30.322 INFO 30556 --- [ main] ConditionEvaluationReportLoggingListener : Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.2019-01-21 22:19:30.333 ERROR 30556 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter : ***************************APPLICATION FAILED TO START***************************Description:An attempt was made to call the method javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String; but it does not exist. Its class, javax.servlet.ServletContext, is available from the following locations: jar:file:/C:/Program%20Files%20(x86)/JAVA/JDK/jre/lib/ext/servlet-api.jar!/javax/servlet/ServletContext.class jar:file:/C:/Mavn/maven-repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.14/tomcat-embed-core-9.0.14.jar!/javax/servlet/ServletContext.classIt was loaded from the following location: file:/C:/Program%20Files%20(x86)/JAVA/JDK/jre/lib/ext/servlet-api.jarAction:Correct the classpath of your application so that it contains a single, compatible version of javax.servlet.ServletContextProcess finished with exit code 1</pre>截图为:<br /><img src="https://img3.mukewang.com/5c45dc8a0001b44c05000236.jpg" title="" alt="https://img.mukewang.com/5c45dc8a0001b44c16890797.jpg" /><img src="https://img3.mukewang.com/5c45dca50001f8e405000250.jpg" title="" alt="https://img.mukewang.com/5c45dca50001f8e417630881.jpg" />跪求大佬!!!
回答的内容为:{阿尔法a=你按照我下面的步骤来一遍,应该没问题的。<img src="https://img1.mukewang.com/5c45f4c200016d1d05000353.jpg" title="" alt="https://img3.mukewang.com/5c45f4c200016d1d08350588.jpg" /><img src="https://img2.mukewang.com/5c45f5370001bd1605000472.jpg" title="" alt="https://img3.mukewang.com/5c45f5370001bd1610330975.jpg" /><img src="https://img2.mukewang.com/5c45f5210001323a05000472.jpg" title="" alt="https://img3.mukewang.com/5c45f5210001323a10330975.jpg" /><img src="https://img1.mukewang.com/5c45f5510001fe2005000472.jpg" title="" alt="https://img2.mukewang.com/5c45f5510001fe2010330975.jpg" /><img src="https://img.mukewang.com/5c45f5ac000176e805000271.jpg" title="" alt="https://img1.mukewang.com/5c45f5ac000176e819201039.jpg" />如果成功了,希望采纳,互相获得积分。下面是我的pom.xml文件,你可以对比一下。如果还有问题,在这里回复我。<pre class="brush:xml;toolbar:false"><?xml version="1.0" encoding="UTF-8"?><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> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.2.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.example</groupId> <artifactId>demo</artifactId> <version>0.0.1-SNAPSHOT</version> <name>demo</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build></project></pre>, qq_沉稳_3=加了tomcat之后报错<img src="https://img2.mukewang.com/5c46e4ad000104b705000273.jpg" title="" alt="https://img4.mukewang.com/5c46e4ad000104b719201048.jpg" />}
指向下一个链接地址为:http://www.imooc.com/wenda/detail/493284
问题为:如何成功的连接到数据库中?
问题地址为:http://www.imooc.com/wenda/detail/493284
问题的表述为: <img src="https://img3.mukewang.com/5c46e3cb00011e4305000167.jpg" title="" alt="https://img2.mukewang.com/5c46e3cb00011e4311090369.jpg" />没办法和老师一样在数据库中成功的建表,还望大牛指点一下子,万分感谢!!
回答的内容为:{阿尔法a=首先看一下你的本地数据库账号密码对不对,然后在resources下新建一个application-dev.yml,把jpa和DataSource的配置放在这个文档里<img src="https://img1.mukewang.com/5c46f7770001115103630215.jpg" title="" alt="https://img.mukewang.com/5c46f7770001115103630215.jpg" />, 比格Pick=<img src="https://img.mukewang.com/5c47c19300014e8c05000363.jpg" title="" alt="https://img1.mukewang.com/5c47c19300014e8c09400682.jpg" />密码与·账户是正确的 ,也新建了一个application.dev.yml,但是还是没有建表成功}
指向下一个链接地址为:http://www.imooc.com/wenda/detail/493069