13372

Spring Boot JSP 404.Whitelabel Error Page

Can't load a very simple JSP page with spring-boot, getting 404 Not Found

HmisApplication.class

@SpringBootApplication public class HmisApplication extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(HmisApplication.class); } public static void main(String[] args) throws Exception { SpringApplication.run(HmisApplication.class, args); } }

MainController.java

@Controller public class WelcomeController { @RequestMapping("/") public String home(Map<String, Object> model) { model.put("message", "HowToDoInJava Reader !!"); return "index"; } @RequestMapping("/next") public String next(Map<String, Object> model) { model.put("message", "You are in new page !!"); return "next"; } }

application.properties

spring.profiles.active=dev,build-info server.contextPath=/hmis server.port=7070 spring.metrics.export.enabled=true spring.main.banner-mode=off spring.mvc.view.prefix: /WEB-INF/jsp/ spring.mvc.view.suffix: .jsp application.message: Hello Phil # HTTP encoding (HttpEncodingProperties) spring.http.encoding.force-request=true spring.http.encoding.charset=UTF-8 spring.http.encoding.enabled=true spring.http.encoding.force=true

pom.xml

<?xml version="1.0" encoding="UTF-8"?>

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<groupId>com.hmis</groupId> <artifactId>hmis</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <name>hmis</name> <description>Demo project for Spring Boot</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.3.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.activiti</groupId> <artifactId>activiti-spring-boot-starter-basic</artifactId> <version>5.21.0</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <!-- <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <!-- Tomcat Embed --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <!--<scope>provided</scope>--> </dependency> <!-- JSTL --> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> </dependency> <!-- To compile JSP files --> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> <scope>provided</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <useSystemClassLoader>false</useSystemClassLoader> </configuration> </plugin> </plugins> </build>

MvcConfiguration.java

@Configuration @EnableWebMvc @ComponentScan public class MvcConfiguration extends WebMvcConfigurerAdapter { @Override public void configureViewResolvers(ViewResolverRegistry registry) { InternalResourceViewResolver resolver = new InternalResourceViewResolver(); resolver.setPrefix("/WEB-INF/jsp/"); resolver.setSuffix(".jsp"); resolver.setViewClass(JstlView.class); registry.viewResolver(resolver); } }

File Structure

├── src ├── main │ ├── java │ │ └── com │ │ └── hmis │ │ ├── HmisApplication.java │ │ ├── MvcConfiguration.java │ │ ├── WelcomeController.java │ └── resources │ └── application.properties │ └── webapp │ └── WEB-INF │ └── jsp │ └── index.jsp │ └── next.jsp

Answer1:

I solved problem after some changing pom.xml

<groupId>com.hmis</groupId> <artifactId>hmis</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <name>hmis</name> <description>Demo project for Spring Boot</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.3.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.activiti</groupId> <artifactId>activiti-spring-boot-starter-basic</artifactId> <version>5.21.0</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <!-- Tomcat Embed --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <!--<scope>provided</scope>--> </dependency> <!-- JSTL --> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> <!-- To compile JSP files --> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> <!--<scope>provided</scope>--> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>

Recommend

  • Genetic Algorithm for Flow shop Scheduling
  • spring boot automatically create database schema Error
  • Setting @Table in run time Spring
  • Toggle menu Button doesn't open sliding menu and shuts down app
  • XSLT: 'value-of select' using keys and conditions?
  • percent (%) width rendered differently in different browser (firefox, safari, opera, chrome)
  • When will it become active on admob at Android app
  • Exit from a loop that contains time delay immediately after a key is pressed
  • How to display attributed text in a UITextView with NSTextContainer and NSTextStorage
  • How to connect localhost:3306 of mysql container via app container- docker
  • Deploying pre-encrypted configuration files to a production environment
  • How to bind comma separated list of values to List
  • Instanciate service on startup in Angular2
  • How to get google-services.json from Developer console?
  • How to check disabled jobs with Jenkins server?
  • get passwords from chrome
  • How to protect an asp:textbox from user input?
  • Search files(key) in s3 bucket takes longer time
  • Fat binaries in iOS
  • What does Main.1 output file do in XCode?
  • Building jamvm 1.5.4 on OS X Lion
  • runtime error when linking ffmpeg libraries in qt creator
  • How to request unsampled report from Google Analytics Management API using Google Apps Script?
  • android Navigation Bar hiding and persantage of usable screen overlap
  • Mixing WebForms and MVC: What should I do with the MasterPage?
  • Getting media player state in windows phone 7
  • Validate child input components on submit with Vee-Validate and vue js 2
  • Intel-64 and ia32 atomic operations acquire-release semantics and GCC 5+
  • Webgrid not refreshing after delete MVC
  • How do I get HTML corresponding to current DOM tree?
  • MVC3 Razor - ListBox pre-select not working
  • Can Jackson SerializationFeature be overridden per field or class?
  • How to show dropdown in excel using jrxml (jasper api)?
  • Cannot Parse HTML Data Using Android / JSOUP
  • NSLayoutConstraint that would pin a view to the bottom edge of a superview
  • How get height of the a view with gone visibility and height defined as wrap_content in xml?
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Getting Messege Twice Using IMvxMessenger
  • Observable and ngFor in Angular 2
  • How to load view controller without button in storyboard?