localhost 8050 page not found.Fix this. Spring Boot…
- User
localhost 8050 page not found.Fix this. Spring Boot "application.properties":spring.datasource.url=jdbc:mysql://localhost:3306/springbootcrud spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.username=root spring.datasource.password=7788 server.port=8050 Interface "User Repository": import net.crud.springbootcrud.model.User; import org.springframework.data.jpa.repository.JpaRepository;
public interface UserRepository extends JpaRepository<User, Long> { } Java file "UserController": import net.crud.springbootcrud.model.User; import net.crud.springbootcrud.service.UserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping;
import java.util.List;
@Controller public class UserController { private final UserService userService;
codepublic UserController(UserService userService) { this.userService = userService; } @GetMapping("/users") public String findAll(Model model){ List<User> users = userService.findAll(); model.addAttribute("users",users); return "user-list"; }@GetMapping("/user-create") public String createUserForm(User user){ return "user-create"; } @PostMapping("/user-create") public String createUser(User user){ userService.saveUser(user); return "redirect:/users"; } }
Java file "User": import jakarta.persistence.*; import lombok.Data;@Data @Entity @Table(name = "users") public class User { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Column(name = "first name") private String firstName; @Column(name = "last name") private String lastName; @Column(name = "username") private String username;
codepublic String getUsername() { return username; }} Java file "UserService": import net.crud.springbootcrud.model.User; import net.crud.springbootcrud.repository.UserRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service;
import java.util.List; import java.util.Optional;
@Service public class UserService { private final UserRepository userRepository;
code - Assistant
To fix the issue, please follow these steps:
-
Check if the Spring Boot application is running on port 8050 by opening a web browser and navigating to . If the application is running, you should see a page with a message "Whitelabel Error Page".
-