При старте web приложения на String Boot отображается только пустая страница и в консоли:
"Cannot forward to error page for request as the response has already been committed. As a result, the response may have the wrong status code"
Помогите, пожалуйста, разобраться:
(ссылка на github https://github.com/Avvilenn/MySpringBootApp )
вот структура проекта:
Класс с методом main:
@SpringBootApplication
public class SwingBootWebApp extends SpringBootServletInitializer {
public SwingBootWebApp() {
super();
setRegisterErrorPageFilter(false);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(SwingBootWebApp.class);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(SwingBootWebApp.class, args);
}
}
конфигурация:
@Configuration
@EnableWebMvc
public class ApplicationWebMvcConfig extends WebMvcConfigurerAdapter {
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler(
"/css/**",
"/fonts/**",
"/js/**"
).addResourceLocations(
"/css/",
"/fonts/",
"/js/"
).resourceChain(true)
.addResolver(new PathResourceResolver());
super.addResourceHandlers(registry);
}
@Bean
public InternalResourceViewResolver viewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/");
resolver.setSuffix(".jsp");
return resolver;
}
контроллер:
@Controller
public class PersonController {
@Autowired
private PersonService service;
@RequestMapping("/")
public String welcome (Model model){
List<Person> personList = service.getAll();
model.addAttribute("PERSONS", personList);
return "welcome";
}}
applicaton.properties:
spring.datasource.url = jdbc:mysql://localhost:3306/opinion
spring.datasource.username = root
spring.datasource.password = root
spring.datasource.testWhileIdle = true
spring.datasource.validationQuery = SELECT 1
spring.jpa.show-sql = true
spring.jpa.hibernate.ddl-auto = update
spring.jpa.hibernate.naming-strategy =org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.properties.hibernate.dialect =org.hibernate.dialect.MySQL5Dialect
spring.mvc.view.suffix=.jsp
pom.xml
<modelVersion>4.0.0</modelVersion>
<groupId>com.elena.mySpringBootApp</groupId>
<artifactId>MySpringBootApp</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.1.RELEASE</version>
</parent>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<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>
<!-- MYSQL -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.4</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>2.1.4</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
/src/main/webapp/WEB-INF/views/
при этом в конфигах ставится/WEB-INF/views/
. А у вас jsp находятся вresources
. Перенестие все в папку/src/main/webapp/WEB-INF/views/
и должно заработать