Thymeleafを使った顧客情報の表示と削除、編集を行うアプリケーションの製作途中で、このエラーが起こってしまいました。
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2020-10-20 09:25:01.705 ERROR 12452 --- [ main] o.s.boot.SpringApplication : Application run failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE] at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:650) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE] ... 20 common frames omitted Caused by: java.lang.NullPointerException: null at net.sf.log4jdbc.Log4jdbcProxyDataSource.getConnection(Log4jdbcProxyDataSource.java:89)
CustomerRepository.java
package com.example.repository; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.jdbc.core.namedparam.SqlParameterSource; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import com.example.domain.Customer; @Repository @Transactional public class CustomerRepository { @Autowired NamedParameterJdbcTemplate jdbcTemplate; private static final RowMapper<Customer> customerRowMapper = (rs,i) ->{ Integer id = rs.getInt("id"); String firstName = rs.getString("first_name"); String lastName = rs.getString("last_name"); return new Customer(id, firstName, lastName); }; @SuppressWarnings("unchecked") public Page<Customer> findAll(){ List<Customer> Customers = jdbcTemplate.query("SELECT id,first_name FROM customers ORDERBY id", customerRowMapper); return (Page<Customer>) Customers; } public Customer findOne(Integer id) { SqlParameterSource param = new MapSqlParameterSource().addValue("id", id); return jdbcTemplate.queryForObject("SELECT id,first_name,last_name FROM customers WHEREid =:id", param, customerRowMapper); } public Customer save(Customer customer) { SqlParameterSource param = new BeanPropertySqlParameterSource(customer); if(customer.getId() == null) { jdbcTemplate.update("INSERT INTO customers (first_name,last_name) values(:firstName, :lastName,)",param); }else { jdbcTemplate.update("UPDATE customers SET first_name =:first_name, last_name =:last_name WHERE is =:id",param); } return customer; } public void delete(Integer id) { SqlParameterSource param = new MapSqlParameterSource().addValue("id", id); jdbcTemplate.update("DELETE FROM customers WHERE id=:id",param); } }
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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.3.4.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.example</groupId> <artifactId>hajiboot-thymeleaf</artifactId> <version>1.0.0-SNAPSHOT</version> <name>hajiboot-thymeleaf</name> <description>Demo project for Spring Boot</description> <properties> <java.version>11</java.version> <vaadin.version>14.4.0</vaadin.version> </properties> <dependencies> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-entitymanager</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> </dependency> <dependency> <groupId>org.lazyluke</groupId> <artifactId>log4jdbc-remix</artifactId> <version>0.2.7</version> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-rest</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jersey</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-web-services</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-webflux</artifactId> </dependency> <dependency> <groupId>com.vaadin</groupId> <artifactId>vaadin-spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-rest-hal-explorer</artifactId> </dependency> <dependency> <groupId>org.springframework.session</groupId> <artifactId>spring-session-core</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>io.projectreactor</groupId> <artifactId>reactor-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>javax.xml.bind</groupId> <artifactId>jaxb-api</artifactId> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>com.vaadin</groupId> <artifactId>vaadin-bom</artifactId> <version>${vaadin.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>springloaded</artifactId> <version>1.2.1.RELEASE</version> </dependency> </dependencies> </plugin> </plugins> </build> </project>
STSを使って作成起動は行っております
文字数制限で載せられませんがcontorollerなど別のファイルもあります。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/10/20 04:02
2020/10/20 04:04