Issue
Already been on these topics but haven't worked for me:
- Topic1 No
@EnableWebMvc
annotation in my project
This is the dependency i used for Thymeleaf
:
<!-- https://mvnrepository.com/artifact/org.thymeleaf/thymeleaf -->
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
<version>3.0.11.RELEASE</version>
</dependency>
- My new Controller named
ViewController
package myrest.Viewcontroller;
//Imports
@Controller
public class ViewController {
public static String uploadDirectory = System.getProperty("user.dir")+"/uploads";
@RequestMapping("/uploadendpoint")
public String uploadPage(Model model)
{
return "uploadView";
}
}
- The
HTML
nameduploadView.html
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8"></meta>
<title>Insert title here</title>
</head>
<body>
<form action = "/upload" method="post" enctype="multipart/form-data">
<input type="file" name="files" multiple>
<input type="submit" value="Upload Files"></input>
</form>
</body>
</html>
- Project's structure:
My Comments: I'm still getting a Whitelabel Error Page , at localhost:8082/uploadendpoint
Edit1:
My @SpringBootApplication
class
package myrest;
import java.io.File;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import myrest.Viewcontroller.ViewController;
import myrest.controller.MainController;
@SpringBootApplication
public class RemoteapiApplication {
public static void main(String[] args) {
new File(ViewController.uploadDirectory).mkdir();
SpringApplication.run(RemoteapiApplication.class, args);
}
}
application.properties
file:
server.port:8082
spring.servlet.multipart.max-file-size=15MB
spring.servlet.multipart.max-request-size=15MB
Server's logs
2020-01-07 14:37:56.708 INFO 9317 --- [ restartedMain] myrest.RemoteapiApplication : Starting RemoteapiApplication on ZenbookPro with PID 9317 (/home/pihill/Documents/workspace-sts-3.9.9.RELEASE/remoteapi/target/classes started by pihill in /home/pihill/Documents/workspace-sts-3.9.9.RELEASE/remoteapi)
2020-01-07 14:37:56.708 INFO 9317 --- [ restartedMain] myrest.RemoteapiApplication : No active profile set, falling back to default profiles: default
2020-01-07 14:37:56.770 WARN 9317 --- [ restartedMain] org.apache.tomcat.util.modeler.Registry : The MBean registry cannot be disabled because it has already been initialised
2020-01-07 14:37:56.781 INFO 9317 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8082 (http)
2020-01-07 14:37:56.782 INFO 9317 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-01-07 14:37:56.782 INFO 9317 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.29]
2020-01-07 14:37:56.784 INFO 9317 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-01-07 14:37:56.784 INFO 9317 --- [ restartedMain] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 75 ms
2020-01-07 14:37:56.801 INFO 9317 --- [ restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-01-07 14:37:56.814 INFO 9317 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2020-01-07 14:37:56.820 INFO 9317 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8082 (http) with context path ''
2020-01-07 14:37:56.820 INFO 9317 --- [ restartedMain] myrest.RemoteapiApplication : Started RemoteapiApplication in 0.119 seconds (JVM running for 2930.389)
2020-01-07 14:37:56.821 INFO 9317 --- [ restartedMain] .ConditionEvaluationDeltaLoggingListener : Condition evaluation unchanged
2020-01-07 14:37:59.725 INFO 9317 --- [nio-8082-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2020-01-07 14:37:59.726 INFO 9317 --- [nio-8082-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2020-01-07 14:37:59.727 INFO 9317 --- [nio-8082-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 1 ms
Whitelabel error page:
Solution
It is like M.Deinum said. You are using Spring Boot so get the benefits from using the starter packages. In the spring-boot-starter-thymleaf package are more dependencies included than just in the org.thymeleaf 3.0.11.RELEASE.
Replace this in your pom.xml:
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
<version>3.0.11.RELEASE</version>
</dependency>
with this:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
Then it works like charming.
Answered By - MoritzMeinhardt
Answer Checked By - Katrina (JavaFixing Volunteer)