i am trying to make web app with spring boot, i've spent much time, looked many posts and articles, and still can't make redirect to my jsp, what am i doing wrong?. That's i have:
my project structure (I can't post image):
https://i.sstatic.net/z7CYR.png
pom.xml:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</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-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-remote-shell</artifactId>
</dependency>
</dependencies>
application.properties:
spring.mvc.view.prefix: /WEB-INF/jsp/
spring.mvc.view.suffix: .jsp
spring.session.store-type=none
spring.datasource.url:jdbc:mysql://localhost/phonebook?useSSL=false
spring.datasource.username:root
spring.datasource.password:root
spring.datasource.driver:com.mysql.jdbc.Driver
spring.jpa.properties.hibernate.dialect:org.hibernate.dialect.MySQL5Dialect
logging.level.org.hibernate.SQl:debug
class WebMvcConfig:
@Configuration
//@EnableWebMvc
public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Override
public void configureDefaultServletHandling(
DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
@Bean
public InternalResourceViewResolver viewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("WEB-INF/jsp/");
resolver.setSuffix(".jsp");
return resolver;
}
Controller :
@Controller
public class MainController {
@RequestMapping(value = "/index", method = RequestMethod.GET)
@ResponseBody
public String index() {
return "index";
}
}
SpringBootApplication :
//@Configuration
//@ComponentScan
//@EnableAutoConfiguration
@SpringBootApplication
public class PhoneBookApplication extends SpringBootServletInitializer{
public static void main(String[] args) {
SpringApplication.run(PhoneBookApplication.class, args);
}
}
After deleting @ResponseBody from my Controller I got this exception:
There was an unexpected error (type=Internal Server Error, status=500). Error resolving template "index", template might not exist or might not be accessible by any of the configured Template Resolvers
@ResponseBodyfrom yourMainControllerif you want to return index.html