Failed to load resource: the server responded with a status of 404 Spring Boot

try to change this:

@RequestMapping(value = "api/users", method = RequestMethod.POST) public void insertUser(@RequestBody User user){ userDao.insertar(user); }

with this:

@RequestMapping(value = "insacol/static/api/users", method = RequestMethod.POST) public void insertUser(@RequestBody User user){ userDao.insertar(user); }

The problem should be related to the URL you invoke;

The issue is with the baseUrl, you need to use = (used for initialization) instead of : (used in typescript to define an objects type). Since you are never really initializing the variable with proper url, request is going to some random url like http://localhost:4200/undefined causing 404. You can update the url as follows and try:

private baseUrl = "http://localhost:8080/evaluationController/notes";

Failed to load resource: the server responded with a status of 404. Whitable Error page in springboot

Questions : Failed to load resource: the server responded with a status of 404. Whitable Error page in springboot

2022-08-01T03:04:05+00:00 2022-08-01T03:04:05+00:00

665

I am using spring boot for my application anycodings_spring-boot when I run it it show me an error This anycodings_spring-boot application has no explicit mapping for anycodings_spring-boot /error, so you are seeing this as a anycodings_spring-boot fallback.

Sat Jun 06 11:44:29 IST 2020 There was an anycodings_spring-boot unexpected error (type=Not Found, anycodings_spring-boot status=404). No message available I use my anycodings_spring-boot sql for database and sql youg for anycodings_spring-boot database editor but it is not able to anycodings_spring-boot connect with database

pom.xml

<?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.0.1.RELEASE</version> <relativePath /> <!-- lookup parent from repository --> </parent> <groupId>com.material</groupId> <artifactId>MaterialComp</artifactId> <version>0.0.1-SNAPSHOT</version> <name>MaterialComp</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.18</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <optional>true</optional> </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>

UserEntity.java

package com.material.Entity; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; @Entity @Table(name="userentity") public class UserEntity { @Id @Column(name="id") @GeneratedValue(strategy=GenerationType.IDENTITY) private Long id; @Column(name="name") private String name; @Column(name="password") private String password; @Column(name="type") private String type; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getType() { return type; } public void setType(String type) { this.type = type; } }

UserRepo.java

package com.material.Repo; import org.springframework.data.jpa.repository.JpaRepository; import com.material.Entity.UserEntity; public interface UserRepository extends JpaRepository<UserEntity, Long>{ }

controller.java

package com.material.Controller; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.material.Entity.UserEntity; import com.material.Repo.UserRepository; @RestController @CrossOrigin(origins= "http://localhost:4200") @RequestMapping(path="user") public class UserController { @Autowired private UserRepository userRepo; @GetMapping("/get") public List<UserEntity> getUsers(){ return userRepo.findAll(); } }

application.properties

spring.datasource.url=jdbc:mysql://localhost/ecommerce spring.datasource.username=root spring.datasource.password= spring.jpa.hibernate.ddl-auto=create-drop spring.jpa.hibernate.use-new-id-generator-mappings=false

Total Answers 1

24

Answers 1 : of Failed to load resource: the server responded with a status of 404. Whitable Error page in springboot

There's a few tricky things here.

Firstly, you've configured your server anycodings_spring-boot to listen on localhost:4200, which is anycodings_spring-boot fine. You've done that with this line:

@CrossOrigin(origins= "http://localhost:4200")

Next you've told spring this:

@RequestMapping(path="user")

Spring will take user and add it to anycodings_spring-boot http://localhost:4200. So it's listening anycodings_spring-boot now on http://localhost:4200user - this anycodings_spring-boot isn't what you want, try adding a / so anycodings_spring-boot that your request mapping looks like anycodings_spring-boot this:

@RequestMapping(path="/user")

Your application should now be listening anycodings_spring-boot on http://localhost:4200/user. Great!

Next, to hit the getUsers method, you've anycodings_spring-boot defined @GetMapping("/get") which, anycodings_spring-boot combined with your other annotations anycodings_spring-boot will mean that to hit getUsers you need anycodings_spring-boot to make a GET to anycodings_spring-boot http://localhost:4200/user/get, assuming anycodings_spring-boot everything was working correctly.

A little trick is that @GetMapping is anycodings_spring-boot actually an alias for anycodings_spring-boot @RequestMapping(method = anycodings_spring-boot RequestMethod.GET) - so to tidy this up anycodings_spring-boot you could delete anycodings_spring-boot @RequestMapping(path="user") and just anycodings_spring-boot use

@GetMapping(value = "/users") and this anycodings_spring-boot would mean that a GET against anycodings_spring-boot http://localhost:4200/user would anycodings_spring-boot activate your getUsers method.

0

2022-08-01T03:04:05+00:00 2022-08-01T03:04:05+00:00Answer Link

mRahman