Spring boot does not generate the json and shows me the white page

makoto :

I've done a simple list with sql server, but it doesn't show me the result, it just shows me the white page. I have no error in the console. Will the sql server 2017 be? please any help?

connection to sql server 2017

spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.datasource.url=jdbc:sqlserver://localhost;databaseName=DB_PRUEBA_V1;integratedSecurity=true
spring.jpa.show-sql=true
#spring.jpa.hibernate.ddl-auto=update
server.port=8090

package app

package app;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class ProyectoV2Application {

    public static void main(String[] args) {
        SpringApplication.run(ProyectoV2Application.class, args);
    }
}

package model

package model;

import java.io.Serializable;

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 = "TB_USERS")
public class Users implements Serializable{

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "COD_USER")
    private int codUser;
    @Column(name = "NOM_USER")
    private String nomUser;
    @Column(name = "EMA_USER")
    private String emUser;

    public int getCodUser() {
        return codUser;
    }
    public void setCodUser(int codUser) {
        this.codUser = codUser;
    }
    public String getNomUser() {
        return nomUser;
    }
    public void setNomUser(String nomUser) {
        this.nomUser = nomUser;
    }
    public String getEmUser() {
        return emUser;
    }
    public void setEmUser(String emUser) {
        this.emUser = emUser;
    }

}

package repository

package repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import model.Users;

@Repository
public interface UserDAO extends JpaRepository<Users, Integer>{

}

service

package service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import model.Users;
import repository.UserDAO;

@Service
public class UserService {
    @Autowired
    private UserDAO dao;

    public List<Users> lista(){
        return dao.findAll();
    }
}

package controller

package controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import model.Users;
import service.UserService;

@RestController
@RequestMapping(value = "/CrudUsers")
public class UserController {
    @Autowired
    private UserService us;

    @ResponseBody
    @GetMapping(path = "/lista", produces = MediaType.APPLICATION_JSON_VALUE)
    public List<Users> lista(){
        return us.lista();
    }
}

Whitelabel Error Page

Deadpool :

Because you created each class in different package like below,

app --> ProyectoV2Application

model --> Users

repository --> UserDAO

service --> UserService

controller --> UserController

But spring boot scans the classes that are either in root package or in sub package of root package, so move all these classes into sub packages of root package

app --> ProyectoV2Application

app.model --> Users

app.repository --> UserDAO

app.service --> UserService

app.controller --> UserController

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=357831&siteId=1