I try to follow the example given by Telusko in this video at 10. JPA | MVC | H2 Example – 01:20:29 : https://www.youtube.com/watch?v=35EQXmHKZYs
I did everything he did with some minor changes (the biggest one is I choose in the new project the "sping web" instead of "web" - because I can't find it). In the 1:25:43 time stamp, Telusko refreshes the localhost:8080/home and can see the form he created, while I see the following error:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Sat Jan 04 14:39:42 IST 2020
There was an unexpected error (type=Not Found, status=404).
No message available
My main is:
package com.stas.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class StockItemsApplication {
public static void main(String[] args) {
SpringApplication.run(StockItemsApplication.class, args);
}
}
My controller is :
package com.stas.demo.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class ItemController {
@RequestMapping("/")
public String home()
{
return "home.jsp";
}
}
My module is :
package com.stas.demo.model;
/*
Read item details (by item no)
Withdrawal quantity of a specific item from stock
Deposit quantity of a specific item to stock
Add item to stock
Delete an item from stock
*/
public class Item
{
int itemNo;
String name;
int amount;
int inventoryCode;
public int getItemNo()
{
return itemNo;
}
public void setItemNo(int itemNo)
{
this.itemNo = itemNo;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public int getAmount()
{
return amount;
}
public void setAmount(int amount)
{
this.amount = amount;
}
public int getInventoryCode()
{
return inventoryCode;
}
public void setInventoryCode(int inventoryCode)
{
this.inventoryCode = inventoryCode;
}
@Override
public String toString()
{
return "Item [itemNo=" + itemNo + ", name=" + name + ", amount=" + amount + ", inventoryCode=" + inventoryCode
+ "]";
}
}
My .jsp is:
<%@ page language="java" contentType="text/html; charset=windows-1255"
pageEncoding="windows-1255"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="windows-1255">
<title>Insert title here</title>
</head>
<body>
<form action = "addItem">
<input type="text" name="itemNo">
<input type="text" name="name">
<input type="text" name="amount">
<input type="text" name="inventoryCode">
<input type="submit">
</form>
</body>
</html>
localhost:8080/home
My dependencies are:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.2.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.assigment</groupId>
<artifactId>StockItems</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>StockItems</name>
<description>Assigment for open legacy</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper</artifactId>
<version>9.0.29</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-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
The strange thing is when I run Telusko's app from git (https://github.com/navinreddy20/Spring-Boot) it does work properly, so I can not understand what I'm missing.
also tried to implement answers from a similar question (Issue With Spring: There was an unexpected error (type=Not Found, status=404)), but none of them worked for me.
I'm almost sure it is because of the "spring web" modifier at the beginning of the project but it was the closest one to the "web" modifier Telusko used - but I don't have it in the list, but maybe I'm wrong and there is something else I missed?
Aucun commentaire:
Enregistrer un commentaire