Spring boot - Unable to allow jsp view

I am trying to create a basic MVC application using Spring boot with Hibernate as ORM and MySql as the database. The problem I am facing is that jsp views are not resolved .

I get a 404 error when trying to get the registration form using a GET request with the following URL:

http://localhost:9000/users/register/

This is the setting that I have in my application.

Directory structure:

 -src -main -java -com ApplicationStart.java -controllers UserController.java -repositories UserRepository.java -webapp -WEB-INF -jsp register.jsp -resources application.properties 

UserController:

 @RestController public class UserController { private UserRepository userRepository; @Autowired public UserController(UserRepository userRepository) { this.userRepository = userRepository; } @RequestMapping(value = "/users/register", method = RequestMethod.GET) public String Register() { return "register"; } } 

Application.properties:

server.port: 9000

spring.datasource.url: jdbc: mysql: // localhost / Contacts

spring.datasource.driverClassName: com.mysql.jdbc.Driver

spring.datasource.username: root

spring.datasource.password:

spring.view.prefix: / WEB-INF / jsp /

spring.view.suffix: .jsp

pom.xml

 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.1.3.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <!-- HIBERNATE --> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-entitymanager</artifactId> </dependency> <!-- MYSQL --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> </dependency> </dependencies> 

MAIN CLASS

 @ComponentScan @Configuration @EnableAutoConfiguration public class ApplicationStart { public static void main(String[] args) { SpringApplication.run(ApplicationStart.class, args); } } 

This is the current setup of my application. Any help on how to solve the problem is greatly appreciated.

Please comment if additional information is required.

Thanks.

+6
source share
1 answer

Spring Boot has limited JSP support due to the use of the built-in servlet container. From the Spring Boot reference documentation:

When running the Spring Boot application, which uses the built-in servlet container (and is packaged as an executable archive), there are some limitations to JSP support.

  • It should work with Tomcat if you use military packaging, i.e. an executable war will work, and will also be deployed in a standard container (not limited to, but including Tomcat). The executable jar will not work due to the hardcoded file template in Tomcat.
  • Jetty does not currently work as an inline container with JSP. There is a JSP sample so you can see how to configure it.

Start by saying that your application has completed the war and make sure that you are using Tomcat (check the log when starting the application). If you have not explicitly indicated that Jetty should be turned on, you are using Tomcat as it is provided by default. Alternatively, try changing your viewing technology, which probably requires more initial work, but can significantly reduce processing time during development, see Hotswapping .

+6
source

Source: https://habr.com/ru/post/971830/


All Articles