Reputation: 173
I am running a spring boot application. When I enter the URL http://localhost:8080
(or http://localhost:8080/index.jsp
)I expect the index.jsp file to load, but I am getting the following error on the browser.
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Sat Mar 05 21:56:33 IST 2016
There was an unexpected error (type=Not Found, status=404).
No message available
My index.jsp is present in webContent directory and my AppConfig class is as follows
@EnableJpaRepositories("com.test.repository")
@Configuration
@EnableTransactionManagement
@ComponentScan(basePackages="com.test.domain")
@PropertySource(value={"classpath:application.properties"})
public class AppConfig {
@Autowired
private Environment environment;
@Bean
public DataSource dataSource() {
DriverManagerDataSource datasource = new DriverManagerDataSource();
datasource.setDriverClassName(environment.getRequiredProperty("spring.datasource.driver-class-name"));
datasource.setUrl(environment.getRequiredProperty("spring.datasource.url"));
datasource.setUsername(environment.getRequiredProperty("spring.datasource.username"));
datasource.setPassword(environment.getRequiredProperty("spring.datasource.password"));
return datasource;
}
@Bean
public ViewResolver getViewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/jsp/");
resolver.setSuffix(".jsp");
return resolver;
}
@Bean
public WebMvcConfigurerAdapter forwarderToIndex() {
return new WebMvcConfigurerAdapter() {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("forward://index.jsp");
}
};
}
}
I also referred this which didn't help me. How do I eliminate this error and redirect to index.jsp?
Upvotes: 2
Views: 5308
Reputation: 1
you can add tomcat jasper dependency in your pom.xml file
<dependency>
<groupId> org.apache.tomcat </groupId>
<artifactId> tomcat-jasper </artifactId>
<version>9.0.5</version>
</dependency>
Upvotes: 0
Reputation: 20155
You can remove Error page auto configuration by using
exclude = { ErrorMvcAutoConfiguration.class }
in your @SpringBootApplication
annotation
i.e
@SpringBootApplication(scanBasePackages = { "com.myapp.app" }, exclude = { ErrorMvcAutoConfiguration.class })
if you are not using
@SpringBootApplication
you can do that by placing in your configuration class
@EnableAutoConfiguration( exclude = { ErrorMvcAutoConfiguration.class })
Upvotes: 2