Spring Redis无法为数据库类型NONE确定嵌入式数据库驱动程序类

Spring Redis无法为数据库类型NONE确定嵌入式数据库驱动程序类,spring,Spring,我正在使用上面的数据加载器在我的redis中加载一些数据 然而,我得到了下面的错误 @Component public class dataloader implements ApplicationRunner { private StudentRepositoryImpl s; @Autowired public dataloader(StudentRepositoryImpl s){ this.s = s; } @Override

我正在使用上面的数据加载器在我的redis中加载一些数据

然而,我得到了下面的错误

@Component
public class dataloader implements ApplicationRunner {

    private StudentRepositoryImpl s;

    @Autowired
    public dataloader(StudentRepositoryImpl s){
        this.s = s;
    }

    @Override
    public void run(ApplicationArguments applicationArguments) throws Exception {

        System.out.println("hi");

        Student student = new Student("Eng2015001", "John Doe", Student.Gender.MALE, 1);
        s.saveStudent(student);

    }
}
我做错了什么?顺便说一下,我的属性文件是空的。非常感谢您的帮助。

试试这个(每个bean对象都应该是@Autowired的,而不仅仅是使用“new”操作符初始化它):

配置类:
@配置
@启用缓存
公共类CacheConfig扩展了CachingConfigurerSupport{
@豆子
公共绝地连接工厂绝地连接工厂(){
JedisConnectionFactory redisConnectionFactory=新的JedisConnectionFactory();
//默认值
setHostName(“127.0.0.1”);
设置端口(6379);
返回连接工厂;
}
@豆子
公共RedisTemplate RedisTemplate(@Autowired-JedisConnectionFactory cf){
RedisTemplate RedisTemplate=新RedisTemplate();
redisTemplate.setConnectionFactory(cf);
返回模板;
}
@豆子
public CacheManager CacheManager(@Autowired RedisTemplate RedisTemplate){
RedisCacheManager cacheManager=新的RedisCacheManager(redisTemplate);
//过期前的秒数。默认为无限制(0)
cacheManager.setDefaultExpiration(300);
返回缓存管理器;
}
}
存储库类
@存储库
公共类StudentRepositoryImpl实现StudentRepository{
私有静态最终字符串KEY=“Student”;
私有再贴现模板;
私人哈希运算;
@自动连线
私有StudentRepositoryImpl(RedisTemplate RedisTemplate){
this.redisTemplate=redisTemplate;
}
@施工后
私有void init(){
hashOps=redisTemplate.opsForHash();
}
公立学校学生(学生){
put(KEY,student.getId(),student);
}
公共无效更新学生(学生){
put(KEY,student.getId(),student);
}
公共学生查找学生(字符串id){
return(Student)hashOps.get(KEY,id);
}
公共地图findAllStudents(){
返回hashOps.entries(键);
}
公共无效删除学生(字符串id){
删除(KEY,id);
}
}
@Repository
public class StudentRepositoryImpl implements StudentRepository {

    private static final String KEY = "Student";

    private RedisTemplate<String, Student> redisTemplate;
    private HashOperations hashOps;

    @Autowired
    private StudentRepositoryImpl(RedisTemplate redisTemplate) {
        this.redisTemplate = redisTemplate;
    }

    @PostConstruct
    private void init() {
        hashOps = redisTemplate.opsForHash();
    }

    public void saveStudent(Student student) {
        hashOps.put(KEY, student.getId(), student);
    }

    public void updateStudent(Student student) {
        hashOps.put(KEY, student.getId(), student);
    }

    public Student findStudent(String id) {
        return (Student) hashOps.get(KEY, id);
    }

    public Map<Object, Object> findAllStudents() {
        return hashOps.entries(KEY);
    }

    public void deleteStudent(String id) {
        hashOps.delete(KEY, id);
    }
}
@Component
public class dataloader implements ApplicationRunner {

    private StudentRepositoryImpl s;

    @Autowired
    public dataloader(StudentRepositoryImpl s){
        this.s = s;
    }

    @Override
    public void run(ApplicationArguments applicationArguments) throws Exception {

        System.out.println("hi");

        Student student = new Student("Eng2015001", "John Doe", Student.Gender.MALE, 1);
        s.saveStudent(student);

    }
}
2017-05-16 10:29:06.238  INFO 7432 --- [           main] c.e.R.RedisCacheExampleApplication       : Starting RedisCacheExampleApplication on PCdessy with PID 7432 (C:\Users\desmond\Desktop\SpringBoot\RedisCacheExample\target\classes started by desmond in C:\Users\desmond\Desktop\SpringBoot\RedisCacheExample)
2017-05-16 10:29:06.242  INFO 7432 --- [           main] c.e.R.RedisCacheExampleApplication       : No active profile set, falling back to default profiles: default
2017-05-16 10:29:06.597  INFO 7432 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@17f23d9: startup date [Tue May 16 10:29:06 SGT 2017]; root of context hierarchy
2017-05-16 10:29:07.830  INFO 7432 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2017-05-16 10:29:07.861  INFO 7432 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2017-05-16 10:29:08.985  INFO 7432 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2017-05-16 10:29:08.995  INFO 7432 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2017-05-16 10:29:08.996  INFO 7432 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.14
2017-05-16 10:29:09.174  INFO 7432 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2017-05-16 10:29:09.174  INFO 7432 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2579 ms
2017-05-16 10:29:09.405  INFO 7432 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
2017-05-16 10:29:09.408  INFO 7432 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'metricsFilter' to: [/*]
2017-05-16 10:29:09.409  INFO 7432 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-05-16 10:29:09.409  INFO 7432 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-05-16 10:29:09.409  INFO 7432 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-05-16 10:29:09.409  INFO 7432 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2017-05-16 10:29:09.409  INFO 7432 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'webRequestLoggingFilter' to: [/*]
2017-05-16 10:29:09.409  INFO 7432 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'applicationContextIdFilter' to: [/*]
2017-05-16 10:29:09.451  WARN 7432 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Tomcat.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.tomcat.jdbc.pool.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. 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).
2017-05-16 10:29:09.453  INFO 7432 --- [           main] o.apache.catalina.core.StandardService   : Stopping service Tomcat
2017-05-16 10:29:09.467  INFO 7432 --- [           main] utoConfigurationReportLoggingInitializer : 

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-05-16 10:29:09.471 ERROR 7432 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
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).


Process finished with exit code 1
@Configuration
@EnableCaching
public class CacheConfig extends CachingConfigurerSupport {

    @Bean
    public JedisConnectionFactory jedisConnectionFactory() {
        JedisConnectionFactory redisConnectionFactory = new JedisConnectionFactory();

        // Defaults
        redisConnectionFactory.setHostName("127.0.0.1");
        redisConnectionFactory.setPort(6379);
        return redisConnectionFactory;
    }

    @Bean
    public RedisTemplate<String, String> redisTemplate(@Autowired JedisConnectionFactory cf) {
        RedisTemplate<String, String> redisTemplate = new RedisTemplate<String, String>();
        redisTemplate.setConnectionFactory(cf);
        return redisTemplate;
    }

    @Bean
    public CacheManager cacheManager(@Autowired RedisTemplate redisTemplate) {
        RedisCacheManager cacheManager = new RedisCacheManager(redisTemplate);

        // Number of seconds before expiration. Defaults to unlimited (0)
        cacheManager.setDefaultExpiration(300);
        return cacheManager;
    }
}
@Repository
public class StudentRepositoryImpl implements StudentRepository {

    private static final String KEY = "Student";

    private RedisTemplate<String, Student> redisTemplate;
    private HashOperations hashOps;

    @Autowired
    private StudentRepositoryImpl(RedisTemplate redisTemplate) {
        this.redisTemplate = redisTemplate;
    }

    @PostConstruct
    private void init() {
        hashOps = redisTemplate.opsForHash();
    }

    public void saveStudent(Student student) {
        hashOps.put(KEY, student.getId(), student);
    }

    public void updateStudent(Student student) {
        hashOps.put(KEY, student.getId(), student);
    }

    public Student findStudent(String id) {
        return (Student) hashOps.get(KEY, id);
    }

    public Map<Object, Object> findAllStudents() {
        return hashOps.entries(KEY);
    }

    public void deleteStudent(String id) {
        hashOps.delete(KEY, id);
    }
}