Раньше я вставлял данные в базу данных MongoDB и сталкивался с некоторыми проблемами; вот мой main.java
Вставить в MongoDB с проблемой Spring backend?
@SpringBootApplication
public class Application {
public static final String DB_NAME = "test";
public static final String USERS_COLLECTION = "users";
public static final String MONGO_HOST = "localhost";
public static final int MONGO_PORT = 27017;
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
try {
MongoClient mongo = new MongoClient(MONGO_HOST, MONGO_PORT);
MongoOperations mongoOps = new MongoTemplate(mongo, DB_NAME);
Test2 p = new Test2("jon");
mongoOps.insert(p, USERS_COLLECTION);
mongo.close();
} catch (UnknownHostException e) {
e.printStackTrace();
}
}}
Вот моя сущность:
@Document
public class Test2 extends DomainBase {
/**
*
*/
private static final long serialVersionUID = -1866079511424097005L;
private Long Id;
private String mail;
public Test2() {
super();
}
public Test2(String mail) {
this.setMail(mail);
}
@Id
@Field("id")
public Long getId() {
return Id;
}
public void setId(Long id) {
Id = id;
}
public String getMail() {
return mail;
}
public void setMail(String mail) {
this.mail = mail;
}
}
А вот мой репозиторий:
public interface Test2Repo extends MongoRepository<Test2, Long> {
}
Я думаю, что это хорошо сделано для этой части, но держать показывая мне те же ошибки:
2016-03-09 15:05:02.194 INFO 19429 --- [ main] .b.l.ClasspathLoggingApplicationListener : Application failed to start with classpath: [file:/home/no-one/workspace/skilify-core/target/classes/, file:/home/no-one/.m2/repository/org/springframework/boot/spring-boot-starter-actuator/1.3.2.RELEASE/spring-boot-starter-actuator-1.3.2.RELEASE.jar, file:/home/no-one/.m2/repository/org/springframework/boot/spring-boot-starter/1.3.2.RELEASE/spring-boot-starter-1.3.2.RELEASE.jar, file:/home/no-one/.m2/repository/org/springframework/boot/spring-boot/1.3.2.RELEASE/spring-boot-1.3.2.RELEASE.jar, file:/home/no-one/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/1.3.2.RELEASE/spring-boot-autoconfigure-1.3.2.RELEASE.jar, file:/home/no-one/.m2/repository/org/springframework/boot/spring-boot-starter-logging/1.3.2.RELEASE/spring-boot-starter-logging-1.3.2.RELEASE.jar, file:/home/no-one/.m2/repository/ch/qos/logback/logback-classic/1.1.3/logback-classic-1.1.3.jar, file:/home/no-one/.m2/repository/ch/qos/logback/logback-core/1.1.3/logback-core-1.1.3.jar, file:/home/no-one/.m2/repository/org/slf4j/jul-to-slf4j/1.7.13/jul-to-slf4j-1.7.13.jar, file:/home/no-one/.m2/repository/org/slf4j/log4j-over-slf4j/1.7.13/log4j-over-slf4j-1.7.13.jar, file:/home/no-one/.m2/repository/org/yaml/snakeyaml/1.16/snakeyaml-1.16.jar, file:/home/no-one/.m2/repository/org/springframework/boot/spring-boot-actuator/1.3.2.RELEASE/spring-boot-actuator-1.3.2.RELEASE.jar, file:/home/no-one/.m2/repository/org/springframework/boot/spring-boot-starter-data-jpa/1.3.2.RELEASE/spring-boot-starter-data-jpa-1.3.2.RELEASE.jar, file:/home/no-one/.m2/repository/org/springframework/boot/spring-boot-starter-aop/1.3.2.RELEASE/spring-boot-starter-aop-1.3.2.RELEASE.jar, file:/home/no-one/.m2/repository/org/aspectj/aspectjweaver/1.8.8/aspectjweaver-1.8.8.jar, file:/home/no-one/.m2/repository/org/springframework/boot/spring-boot-starter-jdbc/1.3.2.RELEASE/spring-boot-starter-jdbc-1.3.2.RELEASE.jar, file:/home/no-one/.m2/repository/org/apache/tomcat/tomcat-jdbc/8.0.30/tomcat-jdbc-8.0.30.jar, file:/home/no-one/.m2/repository/org/apache/tomcat/tomcat-juli/8.0.30/tomcat-juli-8.0.30.jar, file:/home/no-one/.m2/repository/org/springframework/spring-jdbc/4.2.4.RELEASE/spring-jdbc-4.2.4.RELEASE.jar, file:/home/no-one/.m2/repository/org/hibernate/hibernate-entitymanager/4.3.11.Final/hibernate-entitymanager-4.3.11.Final.jar, file:/home/no-one/.m2/repository/org/jboss/logging/jboss-logging/3.3.0.Final/jboss-logging-3.3.0.Final.jar, file:/home/no-one/.m2/repository/org/jboss/logging/jboss-logging-annotations/1.2.0.Beta1/jboss-logging-annotations-1.2.0.Beta1.jar, file:/home/no-one/.m2/repository/org/hibernate/hibernate-core/4.3.11.Final/hibernate-core-4.3.11.Final.jar, file:/home/no-one/.m2/repository/antlr/antlr/2.7.7/antlr-2.7.7.jar, file:/home/no-one/.m2/repository/org/jboss/jandex/1.1.0.Final/jandex-1.1.0.Final.jar, file:/home/no-one/.m2/repository/dom4j/dom4j/1.6.1/dom4j-1.6.1.jar, file:/home/no-one/.m2/repository/xml-apis/xml-apis/1.0.b2/xml-apis-1.0.b2.jar, file:/home/no-one/.m2/repository/org/hibernate/common/hibernate-commons-annotations/4.0.5.Final/hibernate-commons-annotations-4.0.5.Final.jar, file:/home/no-one/.m2/repository/org/hibernate/javax/persistence/hibernate-jpa-2.1-api/1.0.0.Final/hibernate-jpa-2.1-api-1.0.0.Final.jar, file:/home/no-one/.m2/repository/org/javassist/javassist/3.18.1-GA/javassist-3.18.1-GA.jar, file:/home/no-one/.m2/repository/javax/transaction/javax.transaction-api/1.2/javax.transaction-api-1.2.jar, file:/home/no-one/.m2/repository/org/springframework/data/spring-data-jpa/1.9.2.RELEASE/spring-data-jpa-1.9.2.RELEASE.jar, file:/home/no-one/.m2/repository/org/springframework/spring-orm/4.2.4.RELEASE/spring-orm-4.2.4.RELEASE.jar, file:/home/no-one/.m2/repository/org/springframework/spring-aspects/4.2.4.RELEASE/spring-aspects-4.2.4.RELEASE.jar, file:/home/no-one/.m2/repository/org/springframework/boot/spring-boot-starter-security/1.3.2.RELEASE/spring-boot-starter-security-1.3.2.RELEASE.jar, file:/home/no-one/.m2/repository/org/springframework/spring-aop/4.2.4.RELEASE/spring-aop-4.2.4.RELEASE.jar, file:/home/no-one/.m2/repository/aopalliance/aopalliance/1.0/aopalliance-1.0.jar, file:/home/no-one/.m2/repository/org/springframework/security/spring-security-config/4.0.3.RELEASE/spring-security-config-4.0.3.RELEASE.jar, file:/home/no-one/.m2/repository/org/springframework/security/spring-security-core/4.0.3.RELEASE/spring-security-core-4.0.3.RELEASE.jar, file:/home/no-one/.m2/repository/org/springframework/security/spring-security-web/4.0.3.RELEASE/spring-security-web-4.0.3.RELEASE.jar, file:/home/no-one/.m2/repository/org/springframework/spring-core/4.2.4.RELEASE/spring-core-4.2.4.RELEASE.jar, file:/home/no-one/.m2/repository/org/springframework/boot/spring-boot-starter-web/1.3.2.RELEASE/spring-boot-starter-web-1.3.2.RELEASE.jar, file:/home/no-one/.m2/repository/org/springframework/boot/spring-boot-starter-tomcat/1.3.2.RELEASE/spring-boot-starter-tomcat-1.3.2.RELEASE.jar, file:/home/no-one/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/8.0.30/tomcat-embed-core-8.0.30.jar, file:/home/no-one/.m2/repository/org/apache/tomcat/embed/tomcat-embed-el/8.0.30/tomcat-embed-el-8.0.30.jar, file:/home/no-one/.m2/repository/org/apache/tomcat/embed/tomcat-embed-logging-juli/8.0.30/tomcat-embed-logging-juli-8.0.30.jar, file:/home/no-one/.m2/repository/org/apache/tomcat/embed/tomcat-embed-websocket/8.0.30/tomcat-embed-websocket-8.0.30.jar, file:/home/no-one/.m2/repository/org/springframework/boot/spring-boot-starter-validation/1.3.2.RELEASE/spring-boot-starter-validation-1.3.2.RELEASE.jar, file:/home/no-one/.m2/repository/org/hibernate/hibernate-validator/5.2.2.Final/hibernate-validator-5.2.2.Final.jar, file:/home/no-one/.m2/repository/javax/validation/validation-api/1.1.0.Final/validation-api-1.1.0.Final.jar, file:/home/no-one/.m2/repository/com/fasterxml/classmate/1.1.0/classmate-1.1.0.jar, file:/home/no-one/.m2/repository/org/springframework/spring-web/4.2.4.RELEASE/spring-web-4.2.4.RELEASE.jar, file:/home/no-one/.m2/repository/org/springframework/spring-webmvc/4.2.4.RELEASE/spring-webmvc-4.2.4.RELEASE.jar, file:/home/no-one/.m2/repository/org/springframework/mobile/spring-mobile-device/1.1.5.RELEASE/spring-mobile-device-1.1.5.RELEASE.jar, file:/home/no-one/.m2/repository/io/jsonwebtoken/jjwt/0.4/jjwt-0.4.jar, file:/home/no-one/.m2/repository/org/slf4j/slf4j-api/1.7.13/slf4j-api-1.7.13.jar, file:/home/no-one/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.5.3/jackson-databind-2.5.3.jar, file:/home/no-one/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.5.3/jackson-annotations-2.5.3.jar, file:/home/no-one/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.5.3/jackson-core-2.5.3.jar, file:/home/no-one/.m2/repository/com/h2database/h2/1.4.188/h2-1.4.188.jar, file:/home/no-one/.m2/repository/org/apache/commons/commons-lang3/3.0/commons-lang3-3.0.jar, file:/home/no-one/.m2/repository/org/springframework/data/spring-data-mongodb/1.4.1.RELEASE/spring-data-mongodb-1.4.1.RELEASE.jar, file:/home/no-one/.m2/repository/org/springframework/spring-tx/4.2.4.RELEASE/spring-tx-4.2.4.RELEASE.jar, file:/home/no-one/.m2/repository/org/springframework/spring-context/4.2.4.RELEASE/spring-context-4.2.4.RELEASE.jar, file:/home/no-one/.m2/repository/org/springframework/spring-beans/4.2.4.RELEASE/spring-beans-4.2.4.RELEASE.jar, file:/home/no-one/.m2/repository/org/springframework/spring-expression/4.2.4.RELEASE/spring-expression-4.2.4.RELEASE.jar, file:/home/no-one/.m2/repository/org/springframework/data/spring-data-commons/1.11.2.RELEASE/spring-data-commons-1.11.2.RELEASE.jar, file:/home/no-one/.m2/repository/org/mongodb/mongo-java-driver/2.13.3/mongo-java-driver-2.13.3.jar, file:/home/no-one/.m2/repository/org/slf4j/jcl-over-slf4j/1.7.13/jcl-over-slf4j-1.7.13.jar]
я не знаю, в какой части или где проблема действительно проживает, для лучшего анализа здесь является 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- Application information -->
<groupId>**</groupId>
<artifactId>**</artifactId>
<version>1.0-SNAPSHOT</version>
<name>**</name>
<url>**</url>
<inceptionYear>**</inceptionYear>
<!-- Properties information -->
<properties>
<java.version>1.7</java.version>
<spring-boot.version>1.2.3.RELEASE</spring-boot.version>
<spring-framework.version>4.1.6.RELEASE</spring-framework.version>
<jjwt.version>0.4</jjwt.version>
<h2.version>1.4.188</h2.version>
<jackson.version>2.5.3</jackson.version>
<apache-commons.version>3.0</apache-commons.version>
<junit.version>4.12</junit.version>
<jacoco-maven-plugin.version>0.7.5.201505241946</jacoco-maven-plugin.version>
<coveralls-maven-plugin.version>4.1.0</coveralls-maven-plugin.version>
<jongo.version>1.1</jongo.version>
<mongodb-driver.version>2.13.0</mongodb-driver.version>
</properties>
<!-- Parent information -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.2.RELEASE</version>
</parent>
<!-- Dependency information -->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.mobile</groupId>
<artifactId>spring-mobile-device</artifactId>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>${jjwt.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${apache-commons.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<!-- <dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901-1.jdbc4</version>
</dependency> -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>1.4.1.RELEASE</version>
</dependency>
<!-- <dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>${mongodb-driver.version}</version>
</dependency>
<dependency>
<groupId>org.jongo</groupId>
<artifactId>jongo</artifactId>
<version>${jongo.version}</version>
</dependency> -->
</dependencies>
<!-- Build information -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco-maven-plugin.version}</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eluder.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
<version>${coveralls-maven-plugin.version}</version>
</plugin>
</plugins>
</build>
</project>
Пожалуйста, вы могли бы мне помочь?
Можете ли вы попробовать изменить тип от Long до String для MongoRepository? И используйте @Id private String id; в классе? – Jeff
Та же проблема :( –