所以我知道還有其他問題,比如這個,但是我沒有看到我的問題的解決方案。Spring boot + MongoDB - localhost show whitelabel error
希望你們其中一個能看到我做錯了什麼。
當我去到localhost //:8080我得到 「白色標籤錯誤......」
我的pom.xml看起來是這樣的:
<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.mycompany</groupId>
<artifactId>mavenproject1</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>mavenproject1</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
</parent>
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<!--Spring-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.3.10.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.10.RELEASE</version>
</dependency>
<!--MONGO-->
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>1.10.6.RELEASE</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>2.4.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
<!--skal dette bruges?-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>6.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
和我的應用程序類看起來像這樣:
package com.example.mavenproject1;
import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.*;
/**
*
* @author Steffen
*/
@RestController
@EnableAutoConfiguration
@ComponentScan
public class Application {
//Run a function here which dives into the mongoDB and returns the info?
@RequestMapping("/")
String home() {
DBPopulator dbp = new DBPopulator();
dbp.saveNew();
// return dbp.getFil();
return "Hey wassup";
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
而且DBPopulator:
package com.example.mavenproject1;
import java.util.Date;
import java.util.List;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.context.support.GenericXmlApplicationContext;
/**
*
* @author Steffen
*/
public class DBPopulator {
ApplicationContext ctx = new AnnotationConfigApplicationContext(ConnectToDB.class);
MongoOperations mongoOperation = (MongoOperations) ctx.getBean("mongoTemplate");
private int vers = 0;
public void saveNew() {
Fil f = new Fil("fil" + vers + "", new MetaData(new Date(), new Date(), 5));
vers++;
mongoOperation.save(f);
};
public String getFil(){
// query to search user
Query searchQuery = new Query(Criteria.where("filNavn").is("fil1"));
Fil savedF = mongoOperation.findOne(searchQuery, Fil.class);
List<Fil> listFiler = mongoOperation.findAll(Fil.class);
System.out.println("Here is my file: " + savedF);
return "File: " + savedF;
}
}
現在我的應用程序「有效」,因爲它爲我的mongoDB保存了新的「Fil」。我想,在「主頁」功能返回他們在應用類,但到目前爲止,我不能得到任何東西,但「白色標籤錯誤」了......
提前感謝!
**編輯
,並從本地主機//完整的錯誤:8080:
白色標籤錯誤頁面
該應用對/錯誤沒有明確的映射,所以你看到這個作爲後備。 週一8月07 16點39分十八秒CEST 2017年 有意外的錯誤(類型=內部服務器錯誤,狀態= 500)。 com/mongodb/BulkWriteException
請問您可以從控制檯粘貼整個錯誤消息和堆棧跟蹤。 – zombie
嗨@zombie,錯誤消息如下: 白標籤錯誤頁面 此應用程序沒有顯式映射/錯誤,所以您將此視爲後備。 Mon Aug 07 16:39:18 CEST 2017 出現意外錯誤(type = Internal Server Error,status = 500)。 com/mongodb/BulkWriteException 但我沒有在控制檯中得到任何輸出...如果你知道爲什麼這將是一個巨大的幫助! :) –