404 displayed on the front end of the spring cloud project - spring-boot

When doing the graduation project, I tried to use spring cloud to build the framework. In the process of building, due to the limitations of self-study, I did not fully understand some knowledge points, so I encountered many problems. Most of these problems have been solved through the sharing of predecessors on the Internet, but now when I encounter this problem, I have searched a lot of relevant materials on the Internet but failed to find a solution. So I'm asking for help.
After the project starts, when you click on the port Numbers 40999 and 40888 in the run dashboard, the Google browser displays 404, as follows:
enter image description here
But when I access it from the Eureka page, it works
And when I use Google or postman, the page still displays 404 and the error message above.
Many related problems were found on the Internet, including application. Properties configuration and startup class location.
Still hope somebody can help me.thanks.
This is my test controller.
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
#RequestMapping("/test")
#RestController
public class TestController {
#RequestMapping("/hello")
#ResponseBody
public String test(){
return "hello";
}
}
This is the application.properties:
spring.application.name=client
server.port=40999
eureka.client.serviceUrl.defaultZone=http://localhost:20000/eureka/
This is the picture of console log.

Related

HelloRestAPI showing 404 (created with IntelliJ Spring Initializr)

I am totally frustrated about that beginnerproblem
Simply startet a fresh SpringBoot Project with JDK18 and UpToDate IntelliJ.
Inserted no more Code that this Controller:
package com.example.springboot;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
#RestController
public class HelloController {
#GetMapping("/")
public String index() {
return "Greetings from Spring Boot!";
}
}
calling: curl localhost:8080
and get an unusual 404:
The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
Searching for that response pointing me to very old threads talking about views jsp and web.xml
But I dont want to have nasty renderings. I want pure REST-Controller.
Any suggestion to point me to the correct issue or even better to a solution?
The spring-boot-starter-web dependency is required in your pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
When you create a new project with IntelliJ it asks for the dependencies you want to include. Here you need to select "Spring Web":

Registering a resteasy service in a Quarkus extension

I am currently attempting to write my first Quarkus extension, which needs to deploy a rest service. For that purpose I have been looking at the Quarkus tutorial for creating extensions here, and it is pretty close to what I need to do. The problem is that it shows a Servlet, and I would very much like to deploy a RestEasy(Jackson) service instead.
I have created an extension project and added the following service in the runtime module
package my.test.quarkus.extension;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
#Path("/mytest")
public class TestEndpoint {
private static Logger LOGGER = LoggerFactory.getLogger(TestEndpoint.class);
#POST
#Path("/service")
public void testService(){
LOGGER.info("Logit!");
}
}
But the service is not being picked up it seems, as my test returns 404.
package my.test.quarkus.extension.test;
import io.quarkus.test.QuarkusUnitTest;
import io.restassured.RestAssured;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
public class ExtensionTest {
#RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.withEmptyApplication();
#Test
public void testGreeting() {
RestAssured.when().post("/mytest/service").then().statusCode(200);
}
}
I assume i need a BuildItem registering the service inside the deployment project of my extension, but my question is, which BuildItem do i use? Looking at the list of BuildItems there are loads of them, and even filtering those out that has nothing to do with RestEasy, still leaves over 50, most of them without JavaDoc.
If someone can help me with the problem at hand, simply registering a RestEasy service, as well as an interceptor, from an extension, that would be appreciated. And you will get bonus gratitude if you can explain exactly how to navigate through the Quarkus BuildItems when building extensions, because to me it just seems like a jungle of code, but I am guessing I am missing something.

How can I pass my config parameters to the frontend via Spring Boot?

I have a question. I have created 2 config files. I can already use the parameters in the application.properties. My goal is to be able to display and edit the parameters later in the frontend. Like normal settings of any application. Unfortunately, I do not have an exact idea how I can implement this.
Does anyone have an idea for me how I can send my config via RestApi to the frontend?
My application.properties
#ConfigMaintenance
config.maintenance.next-Available-Update-Version=1.28.5
config.maintenance.next-Available-Update-Date= 18.05.2022
config.maintenance.automatic-update= true
config.maintenance.update-Api-Token= sk021=!2jsn?=jacmw
config.maintenance.latest-Version= 1.28.4
#ConfigGeneral
config.general.volume=56
config.general.dark-Mode=false
config.general.night-Mode=false
config.general.fps=144
config.general.screen-Resolution=1920 x 1080
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import lombok.Data;
#Configuration
#ConfigurationProperties(prefix = "config.general")
#Data
public class ConfigGeneral {
private int volume;
private Boolean nightModus;
private Boolean darkMode;
private int fps;
private String screenResolution;
}
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import lombok.Data;
#Configuration
#ConfigurationProperties(prefix = "config.maintenance")
#Data
public class ConfigMaintenance {
private String nextAvailableUpdateVersion;
private String nextAvailableUpdateDate;
private Boolean automaticUpdate;
private String updateApiToken;
private Boolean latestVersion;
}
Basically I would be interested in a solution, but a good report or even just a suggestion would be enough for me :).
Thanks in advance
I have created 2 config files. I can already use the parameters in the
application.properties. My goal is to be able to display and edit the
parameters later in the frontend. Like normal settings of any
application.
I will add my notice here, because the question of how to pass them to UI may be valid but the outcome may be wrong for you.
In a Spring Boot application, the properties that you use and load via #Configuration
#ConfigurationProperties(prefix = "config.general") are loaded only during spring context initialization which happens when the application starts up. So considering that those properties already exist in your application.properties file, your Frontend would not be able to persist the changed properties somewhere.
1 Possible scenario I see for this requirement, is that those properties are loaded from Database and not application.properties, and then when edited the database records are edited to be persistent. Then you have to either restart the application or try to manually refresh the spring context for those properties to take effect. For this solution you could just create an endpoint from your spring-boot application that delivers all properties that exist in database and then another endpoint to edit those properties. Like simple crud operations.
2 Possible scenario but may be a bit overkill is to use cloud config server. Search for spring cloud bus and spring actuator refresh to see how you can apply some out of the box solutions for an application that needs dynamic properties.

Spring-MVC 3.1: How to map URLs with a trailing slash?

I'm converting a legacy servlet application over to Spring 3.1. In the process some URLs are now obsolete. We've had some problems with our network that will not be resolved anytime soon. My boss doesn't want to trust that their redirects will always be operational. So, she asked me to put my own redirects into the webapp.
All works great, except that if a URL has a trailing slash Spring 3.1 will not find the Controller class function that handles it.
http://blah.blah.blah/acme/makedonation gets found, mapped and handled
http://blah.blah.blah/acme/makedonation/ does not
Here is the controller class I am using to handle my legacy URLs
import org.springframework.stereotype.Controller;
import org.springframework.validation.*;
import org.springframework.ui.ModelMap;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.apache.log4j.Logger;
#Controller
public class LegacyServletController {
private static final Logger logger = Logger.getLogger(LegacyServletController.class);
// Redirect these legacy screns "home", the login screen via the logout process
#RequestMapping({"makeadonation","contact","complain"})
public String home() {
logger.debug("started...");
return "redirect:logout";
}// end home()
}// end class LegacyServletController
I Googled around and found this Stack Overflow post that offers several suggestions, but I am new to Spring and do not understand enough of it to implement some of those suggestions. This one in particular sounds like it would be good fit with my needs:
spring 3.1 RequestMappingHandlerMapping allows you to set a
"useTrailingSlashMatch" property. By default it is true. I think
switching it to false would solve your issue,
Would anyone give me a basic example of how to that, quote me a URL that has such an example ( I had no luck with Google ) or point me to a better idea?
Thanks much in advance
Steve
you should configure your bean in context.xml,and set property.
or you can refer to link or spring doc section 16.4
example configuration
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping">
<property name="useTrailingSlashMatch" value="true">
</property>
</bean>
If you are using spring's Java #Configuration you can also just declare a #Bean like this:
#Bean
public RequestMappingHandlerMapping useTrailingSlash() {
return new RequestMappingHandlerMapping() {{ setUseTrailingSlashMatch(true); }};
}

How to get Spring 3.1.1 works with App Engine datastore

Could everyone show me a tutorial on how to make Spring 3.1.1 running on Google App Engine, please?
I've followed severals tutorial and managed to get the dead simple HelloWorld example to work on App Engine. However, when I go futher, I stuck at the persistent process between Spring and Datastore. I looked at this thread Configuring JDO in Spring 3.1?, too, but it works on localhost but it doesn't work when I deploy to app engine due to the javax.naming.NamingException.
Therefore, I'm looking for a not-too-simple tutorial that covers basic aspects of a real life application such as the view, the model and the database.
Jappstart is a good place to see a working example of GAE that uses Spring and the Datastore (via JPA) and is also a good starting point for building a basic GAE/J app.
Having spent about a day trying to make this work, I thought I'd add some additional useful information here. First take a look at this project https://github.com/hleinone/spring-gae-jdo and this issue: http://code.google.com/p/googleappengine/issues/detail?id=1240 -- comment 24 is the useful one.
In case anyone wants to get this working with annotation-driven configuration, here's how I did it:
package com.domain.yourcode.configuration;
import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManagerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.orm.jdo.GAETransactionAwarePersistenceManagerFactoryProxy;
import org.springframework.orm.jdo.JdoTransactionManager;
//import org.springframework.orm.jdo.TransactionAwarePersistenceManagerFactoryProxy;
#Configuration
public class JDOConfiguration {
private static final PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory("transactions-optional");
#Bean
public GAETransactionAwarePersistenceManagerFactoryProxy proxyPmf() {
GAETransactionAwarePersistenceManagerFactoryProxy proxy =
new GAETransactionAwarePersistenceManagerFactoryProxy();
proxy.setTargetPersistenceManagerFactory(pmf);
proxy.setAllowCreate(false);
return proxy;
}
#Bean
public JdoTransactionManager transactionManager() {
JdoTransactionManager mgr = new JdoTransactionManager();
mgr.setPersistenceManagerFactory(pmf);
return mgr;
}
}
You'll still want <tx:annotation-driven/> in your applicationContext.xml

Resources