質問編集履歴
6
テキストの修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -8,6 +8,75 @@
|
|
8
8
|
パッケージの管理がおかしいのか、JPAの仕様がそもそもMultipartFileができないのか、Bean保持ができていないのか。
|
9
9
|
どうか原因と訂正についてご教授ください。
|
10
10
|
|
11
|
+
```pom
|
12
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
13
|
+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
14
|
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
15
|
+
<modelVersion>4.0.0</modelVersion>
|
16
|
+
<parent>
|
17
|
+
<groupId>org.springframework.boot</groupId>
|
18
|
+
<artifactId>spring-boot-starter-parent</artifactId>
|
19
|
+
<version>2.1.8.RELEASE</version>
|
20
|
+
<relativePath/> <!-- lookup parent from repository -->
|
21
|
+
</parent>
|
22
|
+
<groupId>com.example</groupId>
|
23
|
+
<artifactId>Image_Upload_Test</artifactId>
|
24
|
+
<version>0.0.1-SNAPSHOT</version>
|
25
|
+
<name>Image_Upload_Test</name>
|
26
|
+
<description>Demo project for Spring Boot</description>
|
27
|
+
|
28
|
+
<properties>
|
29
|
+
<java.version>1.8</java.version>
|
30
|
+
</properties>
|
31
|
+
|
32
|
+
<dependencies>
|
33
|
+
<dependency>
|
34
|
+
<groupId>org.springframework.boot</groupId>
|
35
|
+
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
36
|
+
</dependency>
|
37
|
+
<dependency>
|
38
|
+
<groupId>org.springframework.boot</groupId>
|
39
|
+
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
40
|
+
</dependency>
|
41
|
+
<dependency>
|
42
|
+
<groupId>org.springframework.boot</groupId>
|
43
|
+
<artifactId>spring-boot-starter-web</artifactId>
|
44
|
+
</dependency>
|
45
|
+
|
46
|
+
<dependency>
|
47
|
+
<groupId>org.springframework.boot</groupId>
|
48
|
+
<artifactId>spring-boot-devtools</artifactId>
|
49
|
+
<scope>runtime</scope>
|
50
|
+
<optional>true</optional>
|
51
|
+
</dependency>
|
52
|
+
<dependency>
|
53
|
+
<groupId>mysql</groupId>
|
54
|
+
<artifactId>mysql-connector-java</artifactId>
|
55
|
+
<scope>runtime</scope>
|
56
|
+
</dependency>
|
57
|
+
<dependency>
|
58
|
+
<groupId>org.projectlombok</groupId>
|
59
|
+
<artifactId>lombok</artifactId>
|
60
|
+
<optional>true</optional>
|
61
|
+
</dependency>
|
62
|
+
<dependency>
|
63
|
+
<groupId>org.springframework.boot</groupId>
|
64
|
+
<artifactId>spring-boot-starter-test</artifactId>
|
65
|
+
<scope>test</scope>
|
66
|
+
</dependency>
|
67
|
+
</dependencies>
|
68
|
+
|
69
|
+
<build>
|
70
|
+
<plugins>
|
71
|
+
<plugin>
|
72
|
+
<groupId>org.springframework.boot</groupId>
|
73
|
+
<artifactId>spring-boot-maven-plugin</artifactId>
|
74
|
+
</plugin>
|
75
|
+
</plugins>
|
76
|
+
</build>
|
77
|
+
|
78
|
+
</project>
|
79
|
+
```
|
11
80
|
```applicationproperties
|
12
81
|
spring.datasource.url=jdbc:mysql://localhost:3306/sampledb
|
13
82
|
spring.datasource.username=root
|
5
テキストの修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
### やりたい事
|
2
|
-
JPAを使ってデータベースに画像を保存させて見たく試しているところです。
|
2
|
+
MultipartFileクラスを使うと保持できると知り、JPAを使ってデータベースに画像を保存させて見たく試しているところです。
|
3
|
-
MultipartFileクラスを使うと保持できると知り、Controller,Service,Repository,Entityクラスを作成した段階です。
|
4
3
|
しかし、org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resourceというエラーが発生し止まってしまっている状態です。
|
5
4
|
|
6
5
|
### 調べた事
|
4
テキストの修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -9,7 +9,15 @@
|
|
9
9
|
パッケージの管理がおかしいのか、JPAの仕様がそもそもMultipartFileができないのか、Bean保持ができていないのか。
|
10
10
|
どうか原因と訂正についてご教授ください。
|
11
11
|
|
12
|
-
|
12
|
+
```applicationproperties
|
13
|
+
spring.datasource.url=jdbc:mysql://localhost:3306/sampledb
|
14
|
+
spring.datasource.username=root
|
15
|
+
spring.datasource.password=XXX
|
16
|
+
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
|
17
|
+
spring.jpa.database=MYSQL
|
18
|
+
spring.jpa.hibernate.ddl-auto=update
|
19
|
+
logging.level.org.springframework.web = trace
|
20
|
+
```
|
13
21
|
```FileUploadForm
|
14
22
|
package com.example.demo.domain;
|
15
23
|
|
3
修正
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
Java SpringBootで、MultipartFile
|
1
|
+
Java SpringBootで、MultipartFileクラスを使いDBに画像を保持する
|
body
CHANGED
File without changes
|
2
テキストの修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -9,32 +9,8 @@
|
|
9
9
|
パッケージの管理がおかしいのか、JPAの仕様がそもそもMultipartFileができないのか、Bean保持ができていないのか。
|
10
10
|
どうか原因と訂正についてご教授ください。
|
11
11
|
|
12
|
-
```FileUploadForm.java
|
13
|
-
package com.example.demo.domain;
|
14
12
|
|
15
|
-
import javax.persistence.Entity;
|
16
|
-
import javax.persistence.GeneratedValue;
|
17
|
-
import javax.persistence.GenerationType;
|
18
|
-
import javax.persistence.Id;
|
19
|
-
|
20
|
-
import org.springframework.web.multipart.MultipartFile;
|
21
|
-
|
22
|
-
import lombok.Getter;
|
23
|
-
import lombok.Setter;
|
24
|
-
|
25
|
-
@Getter
|
26
|
-
@Setter
|
27
|
-
@Entity
|
28
|
-
public class FileUploadForm {
|
29
|
-
@Id
|
30
|
-
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
31
|
-
private Long id;
|
32
|
-
private MultipartFile fileData;
|
33
|
-
|
34
|
-
|
35
|
-
}
|
36
|
-
```
|
37
|
-
```FileUploadForm
|
13
|
+
```FileUploadForm
|
38
14
|
package com.example.demo.domain;
|
39
15
|
|
40
16
|
import javax.persistence.Entity;
|
@@ -59,7 +35,7 @@
|
|
59
35
|
|
60
36
|
}
|
61
37
|
```
|
62
|
-
```HomeController
|
38
|
+
```HomeController
|
63
39
|
ackage com.example.demo.controller;
|
64
40
|
|
65
41
|
|
@@ -91,7 +67,7 @@
|
|
91
67
|
}
|
92
68
|
}
|
93
69
|
```
|
94
|
-
```HomeService
|
70
|
+
```HomeService
|
95
71
|
package com.example.demo.service;
|
96
72
|
|
97
73
|
import org.springframework.beans.factory.annotation.Autowired;
|
@@ -109,7 +85,21 @@
|
|
109
85
|
}
|
110
86
|
}
|
111
87
|
```
|
88
|
+
```HomeRepository
|
89
|
+
package com.example.demo.repository;
|
90
|
+
|
91
|
+
|
92
|
+
import org.springframework.data.jpa.repository.JpaRepository;
|
93
|
+
import org.springframework.stereotype.Repository;
|
94
|
+
|
95
|
+
import com.example.demo.domain.FileUploadForm;
|
96
|
+
|
97
|
+
@Repository
|
98
|
+
public interface HomeRepository extends JpaRepository<FileUploadForm, Long> {
|
99
|
+
}
|
100
|
+
|
101
|
+
```
|
112
|
-
```index
|
102
|
+
```index
|
113
103
|
<!DOCTYPE html>
|
114
104
|
<html xmlns:th="http://www.thymeleaf.org">
|
115
105
|
<head>
|
1
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -34,6 +34,31 @@
|
|
34
34
|
|
35
35
|
}
|
36
36
|
```
|
37
|
+
```FileUploadForm.java
|
38
|
+
package com.example.demo.domain;
|
39
|
+
|
40
|
+
import javax.persistence.Entity;
|
41
|
+
import javax.persistence.GeneratedValue;
|
42
|
+
import javax.persistence.GenerationType;
|
43
|
+
import javax.persistence.Id;
|
44
|
+
|
45
|
+
import org.springframework.web.multipart.MultipartFile;
|
46
|
+
|
47
|
+
import lombok.Getter;
|
48
|
+
import lombok.Setter;
|
49
|
+
|
50
|
+
@Getter
|
51
|
+
@Setter
|
52
|
+
@Entity
|
53
|
+
public class FileUploadForm {
|
54
|
+
@Id
|
55
|
+
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
56
|
+
private Long id;
|
57
|
+
private MultipartFile fileData;
|
58
|
+
|
59
|
+
|
60
|
+
}
|
61
|
+
```
|
37
62
|
```HomeController.java
|
38
63
|
ackage com.example.demo.controller;
|
39
64
|
|
@@ -105,44 +130,4 @@
|
|
105
130
|
|
106
131
|
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not determine type for: org.springframework.web.multipart.MultipartFile, at table: file_upload_form, for columns: [org.hibernate.mapping.Column(file_data)]
|
107
132
|
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1778) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
|
108
|
-
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
|
109
|
-
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
|
110
|
-
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
|
111
|
-
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
|
112
|
-
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
|
113
|
-
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
|
114
|
-
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1105) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
|
115
|
-
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
|
116
|
-
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
|
117
|
-
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
|
118
|
-
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:744) ~[spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
|
119
|
-
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:391) ~[spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
|
120
|
-
at org.springframework.boot.SpringApplication.run(SpringApplication.java:312) ~[spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
|
121
|
-
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) ~[spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
|
122
|
-
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1204) ~[spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
|
123
|
-
at com.example.demo.ImageUploadTestApplication.main(ImageUploadTestApplication.java:10) ~[classes/:na]
|
124
|
-
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
|
125
|
-
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
|
126
|
-
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
|
127
|
-
at java.base/java.lang.reflect.Method.invoke(Method.java:567) ~[na:na]
|
128
|
-
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.1.8.RELEASE.jar:2.1.8.RELEASE]
|
129
|
-
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not determine type for: org.springframework.web.multipart.MultipartFile, at table: file_upload_form, for columns: [org.hibernate.mapping.Column(file_data)]
|
130
|
-
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:402) ~[spring-orm-5.1.9.RELEASE.jar:5.1.9.RELEASE]
|
131
|
-
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:377) ~[spring-orm-5.1.9.RELEASE.jar:5.1.9.RELEASE]
|
132
|
-
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) ~[spring-orm-5.1.9.RELEASE.jar:5.1.9.RELEASE]
|
133
|
-
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1837) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
|
134
|
-
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1774) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
|
135
|
-
... 21 common frames omitted
|
136
|
-
Caused by: org.hibernate.MappingException: Could not determine type for: org.springframework.web.multipart.MultipartFile, at table: file_upload_form, for columns: [org.hibernate.mapping.Column(file_data)]
|
137
|
-
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:486) ~[hibernate-core-5.3.11.Final.jar:5.3.11.Final]
|
138
|
-
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:453) ~[hibernate-core-5.3.11.Final.jar:5.3.11.Final]
|
139
|
-
at org.hibernate.mapping.Property.isValid(Property.java:227) ~[hibernate-core-5.3.11.Final.jar:5.3.11.Final]
|
140
|
-
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:624) ~[hibernate-core-5.3.11.Final.jar:5.3.11.Final]
|
141
|
-
at org.hibernate.mapping.RootClass.validate(RootClass.java:267) ~[hibernate-core-5.3.11.Final.jar:5.3.11.Final]
|
142
|
-
at org.hibernate.boot.internal.MetadataImpl.validate(MetadataImpl.java:347) ~[hibernate-core-5.3.11.Final.jar:5.3.11.Final]
|
143
|
-
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:466) ~[hibernate-core-5.3.11.Final.jar:5.3.11.Final]
|
144
|
-
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:939) ~[hibernate-core-5.3.11.Final.jar:5.3.11.Final]
|
145
|
-
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:57) ~[spring-orm-5.1.9.RELEASE.jar:5.1.9.RELEASE]
|
146
|
-
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) ~[spring-orm-5.1.9.RELEASE.jar:5.1.9.RELEASE]
|
147
|
-
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:390) ~[spring-orm-5.1.9.RELEASE.jar:5.1.9.RELEASE]
|
148
|
-
... 25 common frames omitted
|
133
|
+
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
|