小编Sha*_*kar的帖子

org.springframework.beans.factory.BeanCreationException:创建类路径资源中定义的名称为“scriptDataSourceInitializer”的bean时出错?

我是学习 Spring Boot Web 的新手。我已经开始学习 spring jpa 数据,我使用 h2 数据库。我想使用插入测试数据

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scriptDataSourceInitializer' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceInitializationConfiguration$SharedCredentialsDataSourceInitializationConfiguration.class]: Invocation of init method failed; nested exception is org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #1 of URL [file:/E:/Programing/Java/boot/SpringBootJpa/target/classes/data.sql]: insert into alien values(101,'Rahul','Java'); nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "ALIEN" not found; SQL statement:
insert into alien values(101,'Rahul','Java') [42102-200]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1786) ~[spring-beans-5.3.9.jar:5.3.9]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:602) ~[spring-beans-5.3.9.jar:5.3.9]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524) ~[spring-beans-5.3.9.jar:5.3.9]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.9.jar:5.3.9]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.9.jar:5.3.9]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.9.jar:5.3.9]
    at …
Run Code Online (Sandbox Code Playgroud)

java jpa h2 spring-data-jpa spring-boot

3
推荐指数
1
解决办法
3万
查看次数

org.springframework.beans.BeanInstantiationException:无法实例化

我刚刚开始学习 Spring Boot。我的代码中有一个错误,上面写着

在文件 [E:\Programing\Java\boot\Project1\target\classes\com\example\demo\Alien.class] 中定义名称为“alien”的 bean 创建时出错:bean 实例化失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [com.example.demo.Alien]:构造函数抛出异常;嵌套异常是 java.lang.NullPointerException:无法调用“com.example.demo.Laptop.compile()”,因为“this.laptop”为空

下面是我的代码

主类

package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

@SpringBootApplication
public class Project1Application {

    public static void main(String[] args) {
        ConfigurableApplicationContext context= SpringApplication.run(Project1Application.class, args);
        
        Alien a=context.getBean(Alien.class);
        a.show();
    }

}
Run Code Online (Sandbox Code Playgroud)

异类

package com.example.demo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

@Component
public class Alien {

    private int id;
    private String name;
    private String tech;
    @Autowired
    private Laptop laptop;
    
    public int getId() {
        return id;
    }
    public void setId(int id) …
Run Code Online (Sandbox Code Playgroud)

java spring spring-boot

1
推荐指数
1
解决办法
68
查看次数

标签 统计

java ×2

spring-boot ×2

h2 ×1

jpa ×1

spring ×1

spring-data-jpa ×1