Status 404, not found in SpringBoot with Microservices - java

I am having a problem please hope you can help me it seems that it does not recognize the user class.
{
"timestamp": "2020-03-29T20:22:48.166+0000",
"status": 404,
"error": "Not Found",
"message": "No message available",
"path": "/usuarios"
}
I am performing microservices, one is Zuul server, another is Eureka server and User service. Also I am trying to work the User class (which in a start was in the User service) in a different project as a library (users-commons), in which the User microservice would use it through dependency implementation in pom.xml, I did this because I will also need the User for later microservices so I decouple it.
Project where the user class is located, which will not be a project that runs an application, it will only be a library project.
enter image description here
Application.properties, from the Zuul microservice
spring.application.name = servicio-zuul-server
server.port = 8090
eureka.client.serviceUrl.defaultZone= http://localhost:8761/eureka
zuul.routes.usuarios.service-id=servicio-usuarios
zuul.routes.usuarios.path=/api/usuarios/**
In the User microservice
Uduario.Dao, I am using #RepositoryRestResource, to implement the full Crud automatically
enter image description here
in: SpringbootServicioUsuariosApplication
#SpringBootApplication
#EntityScan({"com.formacionbdi.springboot.app.usuarios.commons.models.entity"})
public class SpringbootServicioUsuariosApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootServicioUsuariosApplication.class, args);
}
}
in the pom.xml of servicio.usuario, the dependency of usuario.commons, which previously generated its jar
<dependency>
<groupId>com.formacionbdi.springboot.app.usuarios.commons</groupId>
<artifactId>springboot-servicio-usuarios-commons</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
I am trying to run: localhost:8090/api/usuarios/usuarios, this is where I get the 404 error.
I have already done this same procedure in another project and I could do it without problems but in this case I don't understand what the problem is. Please hope you can help me.

I had the same problem, this is how I solved:
- First copy the package path that you have declared in your EntityScan and added it to the scanBasePackages attribute from #SpringBootApplication
- You can delete or comment the #EntityScan annotation.
So, it shoud end like that:
#SpringBootApplication(scanBasePackages = "com.formacionbdi.springboot.app.usuarios.commons.models.entity")
//#EntityScan({"com.formacionbdi.springboot.app.usuarios.commons.models.entity"})

Related

java Spring Boot with Swagger - Failed to load remote configuration

I have a Java 11 Spring Boot 2.5.1 application.
Swagger works locally via http:
I have added Swagger, which works perfectly on my localhost:
http://localhost:8085/swagger-ui/index.html#/
Swagger does not work remotely via https:
However, when I deploy it to a remote server, I get the following error:
https://mycompany.co/pow-wow/swagger-ui/index.html#/
Error
Failed to load remote configuration.
note: the remote server is accessed via https.
The REST endpoints are accessible on the remote server.
e.g. GET https://mycompany.co/pow-wow/powwow/test-me returns a 200 as expected.
Question
How do I access the Swagger via the remote server?
Code
pom.xml
<!-- Swagger -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.7</version>
</dependency>
WebSecurityConfig.java
#Configuration
#EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
#Override
protected void configure(HttpSecurity http) throws Exception {
//http.csrf().disable().authorizeRequests().antMatchers("/powwow/*").hasRole("USER").and().httpBasic();
//http.csrf().disable().authorizeRequests().antMatchers("/*").permitAll().and().httpBasic();
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
.authorizeRequests().antMatchers("/soapWS/**").permitAll().and()
.authorizeRequests().antMatchers("/swagger-ui/**", "/v3/api-docs/**").permitAll().and()
.authorizeRequests().antMatchers("/actuator/**").permitAll()
.anyRequest().authenticated().and()
.httpBasic().and()
.csrf().disable();
}
}
More info:
When looking at the network traffic in the browser when accessing Swagger.
Locally, there is a call to:
http://localhost:8085/v3/api-docs/swagger-config
returns:
{"configUrl":"/v3/api-docs/swagger-config","oauth2RedirectUrl":"http://localhost:8085/swagger-ui/oauth2-redirect.html","url":"/v3/api-docs","validatorUrl":""}
Remotely, there is a call to:
https://mycompany.co/v3/api-docs/swagger-config
which returns a 302.
But https://mycompany.co/pow-wow/v3/api-docs/swagger-config
returns:
{"configUrl":"/v3/api-docs/swagger-config","oauth2RedirectUrl":"http://localhost:8085/swagger-ui/oauth2-redirect.html","url":"/v3/api-docs","validatorUrl":""}
So this suggests the issue is related to the /pow-wow context path is missing in the call.
You should try and add
springdoc:
swagger-ui:
config-url: /pow-wow/v3/api-docs/swagger-config
url: /v3/api-docs
to your application.properties. In your provided example
https://mycompany.co/pow-wow/v3/api-docs/swagger-config
it shows that you have "/pow-wow/" in your path. Swagger needs to know where to fetch its config.
Try to add this as well to your security config class
#Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/swagger-ui/**", "/v3/api-docs/**");
}
I had the same issue :
with mvn spring-boot:run : OK
on my local Tomcat server : OK
on the Tomcat server of my organization : KO (Failed to load remote configuration)
The cause was the reverse proxy of my organization that blocked the loop-back call of the application.
To those who are asking:
I had the same issue and this video helped me check it out: https://www.youtube.com/watch?v=A_RWUcTqHBI
Just simple step by step.
Regarding my project to be on the same page:
Spring Boot 3 + Spring Security.
So I:
Added "/swagger-ui/" and "/v3/api-docs/" as #Mohamed suggested to my SecurityFilterChain bean.
Added springdoc-openapi-starter-webmvc-ui dependency in POM.
Configurated SwaggerConfig as follow:
#Configuration
#OpenAPIDefinition
public class SwaggerConfig {
#Bean
public OpenAPI config() {
return new OpenAPI().info(
new Info()
.title("")
.version("")
.description("")
);
}
}
http://localhost:8080/swagger-ui/index.html#/
And it worked smoothly!
Config that helped me:
springdoc:
swagger-ui:
configUrl: /your-service/v3/api-docs/swagger-config
url: /your-service/v3/api-docs
If you have problems with the try it out block (404 error, wrong url), then just use the #OpenAPIDefinition annotation. Kotlin example:
#SpringBootApplication
#OpenAPIDefinition(
info = Info(title = "Your Service API", version = "1.0", description = "Your service description"),
servers = [Server(url = "/your-service", description = "Your Service")]
)
If security config allow swagger, it's because of cashing, try it after clear browser cash or in browser incognito mode.

Spring Cloud Consul Config not working with Spring Boot 2.6.6

I tried to follow the new changes with the latests versions of Spring, where the bootstrap.yaml has been removed, and use the "spring.config.import" property, but I am not able to make my application work (discovery is working fine, but not config server). I am doing so many tries and errors, so it does not make so much sense to copy my current properties, but I will give all the details, so maybe someone is able to identify what is going on:
In my POM, there is already the next dependencies: "spring-cloud-starter-config", "spring-cloud-starter-consul-all", "spring-cloud-starter-consul-discovery" and "spring-cloud-starter-consul-config". Spring Cloud version is "2021.0.1" and Consul "3.1.0".
Main class annotated with #EnableDiscoveryClient
Using "application.properties-development", not YAML, and SPRING_PROFILES_ACTIVE=development
Application name is "profiles"
In my Consul instance, in the "Key / Value" section, I have the next structure: Consul Structure (/config/development/profiles and JSON with the properties to load).
It would be nice that, as with the Cloud Config Server, if no property file is found, it would allow me to run the application.
Thank you in advance.
Cheers!

After deployed the App in Elastic Beanstalk end point of app throws 404 not found in SpringBoot+MySql+Angular app with maven

is literally my first time on AWS deployments , and doing it by myself is harder the task.
After having created my app in Elastic Beans and its respective RDS database with its instance , i created a Snapshot (jar) on my Springboot app which was also implemented in the deployment process of the AWS application.
Also several items were configured in its Software Category referring the RDS database endpoint, server ports, user-name of database , etc...
.
Then after all that process , got the app deployed with a url.
But when i apply that url with the endpoints my springboot controllers have , i receive as error a 404 Not Found; but if i decide to work on local requesting only the RDS database created by the application in Elastic Bean the endpoints shows data and the app works
Literally on my Spring Boot App i declared in the app. properties the connection to that database in AWS
spring.datasource.url=jdbc:mysql://aat54g98qswmf3.clnhc7kmwszz.us-west-2.rds.amazonaws.com:3306/ebdb?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=xxxx
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
logging.level.org.hibernate.SQL=debug
thus my controllers in the spring working in local don't have any problem
#RequestMapping(path = "/restaurant-booking/version1")
public class RestaurantController {
#Autowired
RestaurantService restaurantService;
#ResponseStatus(HttpStatus.OK)
#RequestMapping(value = "/restaurant/all", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
some code.........
};
then on my browser:
But if i switch to the url facilitated by the deployed EB app in AWS, and the use the same endpoint
Any help guys would be amazing , cause honestly can't find the problem or where to look at!
Thanks in advance!!!
The whitelabel error page is the default error page in spring when you have not defined your own. This means your application is deployed and running. You either messed up your request mapping or your url.
If we look at your mappings we see the url should be .../restaurant-booking/version1/restaurant/all
Request mappings get nested when they are on the class and method level.
You actually used the correct url locally but not on your deployed version.
The problem might be arising due to the connectivity with the RDS and the correct Environment configuration for your Spring Boot Application.
I would suggest that prior to continuing with the environment creation (or even after), make sure you connect the RDS properly. For the configuration part:-
you can make use of application-prod.properties file and specify an environment variable and value for software configuration labelled SPRING_PROFILES_ACTIVE and set its value to prod.
The application-prod properties consist of:-
server.port=5000
spring.datasource.url=jdbc:mysql://${RDS_HOSTNAME}:${RDS_PORT}/${RDS_DB_NAME}
spring.datasource.username=${RDS_USERNAME}
spring.datasource.password=${RDS_PASSWORD}
spring.jpa.hibernate.ddl-auto=create
Select a suitable RDS before or after creating the environment.
You need to configure the inbound and outbound rules for security group encompassing the RDS manually to allow access for creating, delete, update, etc.
And then finally upload the jar file in the environment. Worked for me.

Micronaut 2.0.0 "More than 1 route matched the incoming request"

I'm new to the micronaut framework, and I'm trying to get a simple web-app working. The app has one Controller "TestController", with two GET endpoints; one with a parameter and one without:
#Controller("/api/tests")
public class TestController
#Get
public HttpResponse<String> getAll()
#Get("/{id}")
public HttpResponse<String> getUserProfile(#NotBlank #PathVariable("id") long id)
This is just the class and method sigatures
I've generated the initial application code using the Micronaut Launch web-site (https://micronaut.io/launch/), selecting maven and JDK 1.8.
I compile and run the app using "mvn clean compile exec:exec" or "mvn mn:run".
When I attempt to call the endpoint with no parameters: "GET http://localhost:8080/api/tests"
I get: "More than 1 route matched the incoming request. The following routes matched /api/tests: GET - /api/tests, GET - /api/tests"
When I attempt to call the endpoint with a parameter: GET http://localhost:8080/api/tests/1
I get: "Page Not Found"
I'm running on Windows 10, using eclipse Version: 2019-12 (4.14.0) and JDK version 1.8.0_121-b13.
I've modified the POM to include for various micronaut processors. I've installed m2e in Eclipse and selected "Auto configure JDT APT" for annotation processing.
I would be grateful for any assistance on getting this simple application running. I've uploaded the source to Git Hub on https://github.com/phillwatson/upstart-failures
#JeffScottBrown Thank you for taking the time to look at this. Very much appreciated. Your example led me to the solution, although not quite as simple as using 2.0.0.RC2.
The cause of the issue was my inclusion of the micronauts.jaxrs library. Which, comparing your pom, you didn't have. I'm guessing that the jaxrs annotation processing was causing confusion with the micronaut http annotation. Whatever the underlying cause, removing any reference to jaxrs solved the issue.
Thanks again.

Spring Boot 2 Actuator /health endpoint not showing additional info when using authentication

I'm in the midst of migrating a project from Spring Boot 1.X to Spring Boot 2.X. The only thing that's left and that's giving me trouble is the Spring Boot Actuator.
In Spring Boot 1.X when you hit the /health endpoint with credentials, you would normally receive a more detailed list of indicators, like for example the result of the default org.springframework.boot.actuate.health.DiskSpaceHealthIndicator.
{
"status": "UP",
"diskSpace": {
"status": "UP",
"total": 1000240963584,
"free": 909162590208,
"threshold": 10485760
}
}
I would also see custom defined Health indicators here as well.
Now that I use the newer version of the Actuator library, I no longer receive that additional information (when providing credentials). All I see is:
{
"status": "UP"
}
At first I thought that maybe I haven't set up the credentials properly, but by intentionally providing invalid credentials I get 401 Unauthorized. So it can't be the authentication.
I digged in a little deeper with the debugger and saw that the DiskSpaceHealthIndicator bean actually gets created, along with all my other custom defined indicators. But it seems like they do not get registered by Spring Boot for me to not see them when hitting the /health endpoint.
Any suggestions?
The issue was fixed by adding:
management.endpoint.health.show-details=when_authorized
as #ValentinCarnu suggested.
And this is what I found afterwards in the documentation: https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html#production-ready-health
The default value is never. A user is considered to be authorized when they are in one or more of the endpoint’s roles. If the endpoint has no configured roles (the default) all authenticated users are considered to be authorized. The roles can be configured using the management.endpoint.health.roles property.
Thanks!
Don't use this URL http://localhost:8080/env
Instead use http://localhost:8080/actuator/env
And set the Application.properties with the following
management.security.enabled=false
management.endpoints.web.exposure.include=*
Worked for Me

Categories

Resources