質問編集履歴

6

テキストの修正

2019/09/17 12:36

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -18,6 +18,144 @@
18
18
 
19
19
 
20
20
 
21
+ ```pom
22
+
23
+ <?xml version="1.0" encoding="UTF-8"?>
24
+
25
+ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
26
+
27
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
28
+
29
+ <modelVersion>4.0.0</modelVersion>
30
+
31
+ <parent>
32
+
33
+ <groupId>org.springframework.boot</groupId>
34
+
35
+ <artifactId>spring-boot-starter-parent</artifactId>
36
+
37
+ <version>2.1.8.RELEASE</version>
38
+
39
+ <relativePath/> <!-- lookup parent from repository -->
40
+
41
+ </parent>
42
+
43
+ <groupId>com.example</groupId>
44
+
45
+ <artifactId>Image_Upload_Test</artifactId>
46
+
47
+ <version>0.0.1-SNAPSHOT</version>
48
+
49
+ <name>Image_Upload_Test</name>
50
+
51
+ <description>Demo project for Spring Boot</description>
52
+
53
+
54
+
55
+ <properties>
56
+
57
+ <java.version>1.8</java.version>
58
+
59
+ </properties>
60
+
61
+
62
+
63
+ <dependencies>
64
+
65
+ <dependency>
66
+
67
+ <groupId>org.springframework.boot</groupId>
68
+
69
+ <artifactId>spring-boot-starter-data-jpa</artifactId>
70
+
71
+ </dependency>
72
+
73
+ <dependency>
74
+
75
+ <groupId>org.springframework.boot</groupId>
76
+
77
+ <artifactId>spring-boot-starter-thymeleaf</artifactId>
78
+
79
+ </dependency>
80
+
81
+ <dependency>
82
+
83
+ <groupId>org.springframework.boot</groupId>
84
+
85
+ <artifactId>spring-boot-starter-web</artifactId>
86
+
87
+ </dependency>
88
+
89
+
90
+
91
+ <dependency>
92
+
93
+ <groupId>org.springframework.boot</groupId>
94
+
95
+ <artifactId>spring-boot-devtools</artifactId>
96
+
97
+ <scope>runtime</scope>
98
+
99
+ <optional>true</optional>
100
+
101
+ </dependency>
102
+
103
+ <dependency>
104
+
105
+ <groupId>mysql</groupId>
106
+
107
+ <artifactId>mysql-connector-java</artifactId>
108
+
109
+ <scope>runtime</scope>
110
+
111
+ </dependency>
112
+
113
+ <dependency>
114
+
115
+ <groupId>org.projectlombok</groupId>
116
+
117
+ <artifactId>lombok</artifactId>
118
+
119
+ <optional>true</optional>
120
+
121
+ </dependency>
122
+
123
+ <dependency>
124
+
125
+ <groupId>org.springframework.boot</groupId>
126
+
127
+ <artifactId>spring-boot-starter-test</artifactId>
128
+
129
+ <scope>test</scope>
130
+
131
+ </dependency>
132
+
133
+ </dependencies>
134
+
135
+
136
+
137
+ <build>
138
+
139
+ <plugins>
140
+
141
+ <plugin>
142
+
143
+ <groupId>org.springframework.boot</groupId>
144
+
145
+ <artifactId>spring-boot-maven-plugin</artifactId>
146
+
147
+ </plugin>
148
+
149
+ </plugins>
150
+
151
+ </build>
152
+
153
+
154
+
155
+ </project>
156
+
157
+ ```
158
+
21
159
  ```applicationproperties
22
160
 
23
161
  spring.datasource.url=jdbc:mysql://localhost:3306/sampledb

5

テキストの修正

2019/09/17 12:36

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -1,8 +1,6 @@
1
1
  ### やりたい事
2
2
 
3
- JPAを使ってデータベースに画像を保存させて見たく試しているところです。
3
+ MultipartFileクラスを使うと保持できると知り、JPAを使ってデータベースに画像を保存させて見たく試しているところです。
4
-
5
- MultipartFileクラスを使うと保持できると知り、Controller,Service,Repository,Entityクラスを作成した段階です。
6
4
 
7
5
  しかし、org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resourceというエラーが発生し止まってしまっている状態です。
8
6
 

4

テキストの修正

2019/09/17 12:12

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -20,7 +20,23 @@
20
20
 
21
21
 
22
22
 
23
-
23
+ ```applicationproperties
24
+
25
+ spring.datasource.url=jdbc:mysql://localhost:3306/sampledb
26
+
27
+ spring.datasource.username=root
28
+
29
+ spring.datasource.password=XXX
30
+
31
+ spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
32
+
33
+ spring.jpa.database=MYSQL
34
+
35
+ spring.jpa.hibernate.ddl-auto=update
36
+
37
+ logging.level.org.springframework.web = trace
38
+
39
+ ```
24
40
 
25
41
  ```FileUploadForm
26
42
 

3

修正

2019/09/17 12:10

投稿

退会済みユーザー
test CHANGED
@@ -1 +1 @@
1
- Java SpringBootで、MultipartFileDBに画像を保持する
1
+ Java SpringBootで、MultipartFileクラスを使いDBに画像を保持する
test CHANGED
File without changes

2

テキストの修正

2019/09/17 12:08

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -20,7 +20,9 @@
20
20
 
21
21
 
22
22
 
23
+
24
+
23
- ```FileUploadForm.java
25
+ ```FileUploadForm
24
26
 
25
27
  package com.example.demo.domain;
26
28
 
@@ -70,57 +72,7 @@
70
72
 
71
73
  ```
72
74
 
73
- ```FileUploadForm.java
74
-
75
- package com.example.demo.domain;
76
-
77
-
78
-
79
- import javax.persistence.Entity;
80
-
81
- import javax.persistence.GeneratedValue;
82
-
83
- import javax.persistence.GenerationType;
84
-
85
- import javax.persistence.Id;
86
-
87
-
88
-
89
- import org.springframework.web.multipart.MultipartFile;
90
-
91
-
92
-
93
- import lombok.Getter;
94
-
95
- import lombok.Setter;
96
-
97
-
98
-
99
- @Getter
100
-
101
- @Setter
102
-
103
- @Entity
104
-
105
- public class FileUploadForm {
106
-
107
- @Id
108
-
109
- @GeneratedValue(strategy = GenerationType.IDENTITY)
110
-
111
- private Long id;
112
-
113
- private MultipartFile fileData;
114
-
115
-
116
-
117
-
118
-
119
- }
120
-
121
- ```
122
-
123
- ```HomeController.java
75
+ ```HomeController
124
76
 
125
77
  ackage com.example.demo.controller;
126
78
 
@@ -184,7 +136,7 @@
184
136
 
185
137
  ```
186
138
 
187
- ```HomeService.java
139
+ ```HomeService
188
140
 
189
141
  package com.example.demo.service;
190
142
 
@@ -220,7 +172,35 @@
220
172
 
221
173
  ```
222
174
 
175
+ ```HomeRepository
176
+
177
+ package com.example.demo.repository;
178
+
179
+
180
+
181
+
182
+
183
+ import org.springframework.data.jpa.repository.JpaRepository;
184
+
185
+ import org.springframework.stereotype.Repository;
186
+
187
+
188
+
189
+ import com.example.demo.domain.FileUploadForm;
190
+
191
+
192
+
193
+ @Repository
194
+
195
+ public interface HomeRepository extends JpaRepository<FileUploadForm, Long> {
196
+
197
+ }
198
+
199
+
200
+
201
+ ```
202
+
223
- ```index.html
203
+ ```index
224
204
 
225
205
  <!DOCTYPE html>
226
206
 

1

追記

2019/09/17 11:59

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -70,6 +70,56 @@
70
70
 
71
71
  ```
72
72
 
73
+ ```FileUploadForm.java
74
+
75
+ package com.example.demo.domain;
76
+
77
+
78
+
79
+ import javax.persistence.Entity;
80
+
81
+ import javax.persistence.GeneratedValue;
82
+
83
+ import javax.persistence.GenerationType;
84
+
85
+ import javax.persistence.Id;
86
+
87
+
88
+
89
+ import org.springframework.web.multipart.MultipartFile;
90
+
91
+
92
+
93
+ import lombok.Getter;
94
+
95
+ import lombok.Setter;
96
+
97
+
98
+
99
+ @Getter
100
+
101
+ @Setter
102
+
103
+ @Entity
104
+
105
+ public class FileUploadForm {
106
+
107
+ @Id
108
+
109
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
110
+
111
+ private Long id;
112
+
113
+ private MultipartFile fileData;
114
+
115
+
116
+
117
+
118
+
119
+ }
120
+
121
+ ```
122
+
73
123
  ```HomeController.java
74
124
 
75
125
  ackage com.example.demo.controller;
@@ -213,83 +263,3 @@
213
263
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1778) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
214
264
 
215
265
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
216
-
217
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
218
-
219
- at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
220
-
221
- at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
222
-
223
- at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
224
-
225
- at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
226
-
227
- at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1105) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
228
-
229
- at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
230
-
231
- at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
232
-
233
- at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
234
-
235
- at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:744) ~[spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
236
-
237
- at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:391) ~[spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
238
-
239
- at org.springframework.boot.SpringApplication.run(SpringApplication.java:312) ~[spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
240
-
241
- at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) ~[spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
242
-
243
- at org.springframework.boot.SpringApplication.run(SpringApplication.java:1204) ~[spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
244
-
245
- at com.example.demo.ImageUploadTestApplication.main(ImageUploadTestApplication.java:10) ~[classes/:na]
246
-
247
- at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
248
-
249
- at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
250
-
251
- at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
252
-
253
- at java.base/java.lang.reflect.Method.invoke(Method.java:567) ~[na:na]
254
-
255
- at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.1.8.RELEASE.jar:2.1.8.RELEASE]
256
-
257
- 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)]
258
-
259
- at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:402) ~[spring-orm-5.1.9.RELEASE.jar:5.1.9.RELEASE]
260
-
261
- at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:377) ~[spring-orm-5.1.9.RELEASE.jar:5.1.9.RELEASE]
262
-
263
- at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) ~[spring-orm-5.1.9.RELEASE.jar:5.1.9.RELEASE]
264
-
265
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1837) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
266
-
267
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1774) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
268
-
269
- ... 21 common frames omitted
270
-
271
- 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)]
272
-
273
- at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:486) ~[hibernate-core-5.3.11.Final.jar:5.3.11.Final]
274
-
275
- at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:453) ~[hibernate-core-5.3.11.Final.jar:5.3.11.Final]
276
-
277
- at org.hibernate.mapping.Property.isValid(Property.java:227) ~[hibernate-core-5.3.11.Final.jar:5.3.11.Final]
278
-
279
- at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:624) ~[hibernate-core-5.3.11.Final.jar:5.3.11.Final]
280
-
281
- at org.hibernate.mapping.RootClass.validate(RootClass.java:267) ~[hibernate-core-5.3.11.Final.jar:5.3.11.Final]
282
-
283
- at org.hibernate.boot.internal.MetadataImpl.validate(MetadataImpl.java:347) ~[hibernate-core-5.3.11.Final.jar:5.3.11.Final]
284
-
285
- at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:466) ~[hibernate-core-5.3.11.Final.jar:5.3.11.Final]
286
-
287
- at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:939) ~[hibernate-core-5.3.11.Final.jar:5.3.11.Final]
288
-
289
- at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:57) ~[spring-orm-5.1.9.RELEASE.jar:5.1.9.RELEASE]
290
-
291
- at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) ~[spring-orm-5.1.9.RELEASE.jar:5.1.9.RELEASE]
292
-
293
- at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:390) ~[spring-orm-5.1.9.RELEASE.jar:5.1.9.RELEASE]
294
-
295
- ... 25 common frames omitted