Home > front end >  Setting up JdbcTemplate in IDEA Community. Liquibase failure
Setting up JdbcTemplate in IDEA Community. Liquibase failure

Time:04-04

I have working program with JDBC API and want to implement JDBC Template (free version IDEA Community).

In my SpringConfig I add 2 Beans (no other changes) and right after that I receive Errror, when trying to launch the program. The error:

Liquibase failed to start because no changelog could be found at 'classpath:/db/changelog/db.changelog-master.yaml'. Action: Make sure a Liquibase changelog is present at the configured path.

tree structure

What's wrong with it?

I do not do any another changes. Nothing add to application.properties (as far as I understand it is not necessary). In my pom.xml I have: liquibase-core, spring-boot-starter-data-jpa, mysql-connector-java

the SpringConfig:

@Configuration
@ComponentScan ("com.ko")
@EnableWebMvc
public class SpringConfig implements WebMvcConfigurer  {

    private final ApplicationContext applicationContext;

    @Autowired
    public SpringConfig(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }

    @Bean //filter for _method
    public FilterRegistrationBean HiddenHttpMethodFilter (){
        FilterRegistrationBean filterRegBean = new FilterRegistrationBean(new HiddenHttpMethodFilter());
        filterRegBean.setUrlPatterns(Arrays.asList("/*"));
        return filterRegBean;
    }
/*
    @Bean //first variant
    public DataSource datasSource(){
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
        dataSource.setUrl("jdbc:mysql://localhost:3306/javastudy");
        dataSource.setUsername("root");
        dataSource.setPassword("root");
        return dataSource;
    }*/

    @Bean //second variant
    public DataSource datasource() {
        return DataSourceBuilder.create()
                .driverClassName("com.mysql.cj.jdbc.Driver")
                .url("jdbc:mysql://localhost:3306/javastudy")
                .username("root")
                .password("root")
                .build();
    }
    @Bean 
    public JdbcTemplate jdbcTemplate(){
        return new JdbcTemplate(datasource());
    }

}

CodePudding user response:

Since you are using Liquibase dependency in your pom.xml file, you need to make a db.changelog-master.yaml file in order to store all the information related to making new Liquibase scripts and updating or deleting the existing Liquibase scripts. You can create this file in the resources folder of your project. Also if you need you have the option to choose between yaml and xml for creating this file.

  • Related