Home > Back-end >  Spring Endpoints Returning Blank (not error 404)
Spring Endpoints Returning Blank (not error 404)

Time:07-13

Recently, I updated my spring to extend JPARepository and added an actuator and logging, and now my REST endpoints take 10 seconds to load, and return a blank page. Please note, the methods associated with the endpoints run successfully, so when I put in a system.out.print and other DB queries, they execute successfully, but none of the method return to the api endoint. Here are some examples of how my project looks for the entity, repository, service, controller, and application.properties:

Entity:

@Entity
@Table(name = "Example")
@Getter
@Setter
public class ExampleEntity {

//specific code removed for security

}

Repository:

@RepositoryRestResource(exported = false)
public interface ExapleRepository extends JPARepository<ExampleEntity, String> {

}

Service:

   @Service
public class ExampleService {
    @Autowired
    ExampleRepository exampleRepository;
//methods in here
}

Controller:

@RestController
public class ExampleController {

    @GetMapping("/test")
    public String test() {
        System.out.println("running");
return "Test Successful";
//when going to localhost:8081/test, this method will system.out.println running, but postman will run for like 10 seconds, and return nothing
    }

}

Application.properties:

spring.data.jdbc.repositories.enabled=false
#Basic Server IP Settings
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/{dbname}
spring.datasource.username={hidden}
spring.datasource.password={hidden}
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
#server.address=10.0.0.78
#insert ifconfig inet ip
server.port=8081

#Flyway Settings
spring.flyway.baseline-on-migrate=true

#Actuator Settings
management.endpoints.web.base-path=/{hidden}
management.endpoint.health.show-details=always
management.endpoints.web.exposure.include=*

Here are some images for reference...

enter image description here

enter image description here

As you can see, when I go to the endpoint, the method runs successfully, but the string is never successfully returned to the rest endpoint.

enter image description here

CodePudding user response:

I tried with this code everything is fine and it's working well for me. I guess it's postman application problem, was it working fine before for other applications?.. regardless I suggest you reinstall or update it.

Edit: for your information, I'm also having a similar structure as yours like JpaRepository and so on.

CodePudding user response:

I have cloned your controller and it's working fine in my application, it prints both the console and the output on the screen. Try removing the (exported=false) from your repository as @Lakshman Kumar suggests may be that works. I'm attaching the screen shots of your code and its output in my server for your reference,

Output in browser Code snippet and output in console API response in postman

  • Related