描述:com.mongotest.demo.seeder中构造函数的参数0需要类型为“com.mongotest.repositories.studentrepository”的bean,但找不到该bean。
@Document(collection = "Students")
public class Student {
@Id
private String number;
private String name;
@Indexed(direction = IndexDirection.ASCENDING)
private int classNo;
//Constructor and getters and setters.
}
================================
@Repository
public interface StudentRepository extends MongoRepository<Student, String>{
}
================================
@Component
@ComponentScan({"com.mongotest.repositories"})
public class Seeder implements CommandLineRunner{
private StudentRepository studentRepo;
public Seeder(StudentRepository studentRepo) {
super();
this.studentRepo = studentRepo;
}
@Override
public void run(String... args) throws Exception {
// TODO Auto-generated method stub
Student s1 = new Student("1","Tom",1);
Student s2 = new Student("2","Jerry",1);
Student s3 = new Student("3","Kat",2);
studentRepo.deleteAll();
studentRepo.save(Arrays.asList(s1,s2,s3));
}
}
================================
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
pom.xml
<?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>
<groupId>com.mongotest</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.4.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<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>
请在DemoApplication
中添加以下注释
@SpringBootApplication
@ComponentScan("com.mongotest") //to scan packages mentioned
@EnableMongoRepositories("com.mongotest") //to activate MongoDB repositories
public class DemoApplication { ... }
我有一个Java Spring Boot项目,我正在其中创建一个post请求。代码如下所示: 主要: 但是,当我运行该项目时,我会得到以下错误: 感谢您对此的任何帮助!非常感谢,
下午好,我正在尝试使用Spring Boot运行SOAP服务,但出现以下错误: 应用程序启动失败 描述: 我知道也许这应该是个愚蠢的错误,但我看不出来 附件MI代码: SpringBootSoapApp.java ClienteServiceImpl.java client.xsd 应用程序.属性 我的项目结构 我试图遵循以下示例:https://www.javaspringclub.com/pu
当我运行main类时会出错。 错误: 主类: 我的包裹是这样的:
我有 ProductController.java ProductService.java ProductServiceImpl.java 这是我的错误: 我有完整日志:https://gist.github.com/donhuvy/b918e20eeeb7cbe3c4be4167d066f7fd 这是我的完整源代码https://github.com/donhuvy/accounting/com