春季靴子球衣与mongodb投掷错误连接

时间:2017-07-18 11:39:21

标签: java spring mongodb rest spring-boot

我在Spring启动时实现Jersey并遇到错误。

APPLICATION FAILED TO START
***************************

Description:

Cannot determine embedded database driver class for database type NONE

Action:

If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).  

MyRestController.java

@RestController
public class MyRestController {
@Autowired
private UserRepository userRepository;

@RequestMapping(value="/user/",method=RequestMethod.GET)
public ResponseEntity<String> getUserDataInJson(){
    List<User>userList=userRepository.showAll();
    System.out.println(userList.toString());
    return new ResponseEntity<String>(HttpStatus.OK);
}
}  

application.properties文件

spring.data.mongodb.host=localhost
spring.data.mongodb.database=local
spring.data.mongodb.port=27017  

User.java

@Document
public class User {
private String name;
private String city;
public User(String name, String city) {
    super();
    this.name = name;
    this.city = city;
}
public User() {
    super();
}
public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}
public String getCity() {
    return city;
}
public void setCity(String city) {
    this.city = city;
}
@Override
public String toString() {
    return "User [name=" + name + ", city=" + city + "]";
}
}  

RestApiApplication.java文件

@SpringBootApplication(scanBasePackages="org.apedusoft.RestAPI")
public class RestApiApplication {

public static void main(String[] args) {
    SpringApplication.run(RestApiApplication.class, args);
}

}  

UserRepository.java文件

public interface UserRepository extends MongoRepository<User, String>{
List<User> showAll();

}  

UserRepositoryImpl.java文件

public class UserRepositoryImpl implements UserRepository {

// overridded methods

@Autowired
private MongoTemplate mongoTemplate;

@Override
public List<User> showAll() {
    List<User> userList=mongoTemplate.findAll(User.class);
    return userList;
}

}

gradle.build文件

dependencies {
compile('org.springframework.boot:spring-boot-starter-data-mongodb')
compile('org.springframework.boot:spring-boot-starter-jdbc')
compile('org.springframework.boot:spring-boot-starter-jersey')
compile('org.springframework.boot:spring-boot-starter-web')
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
testCompile('org.springframework.boot:spring-boot-starter-test')
}  

无法获取错误,即无法知道错误的位置。无论是在mongodb连接弹簧启动还是在配置中的某个地方。我正在尝试的是使用mongodb作为数据库在spring boot中构建RESTful服务 感谢。

0 个答案:

没有答案