简体   繁体   中英

What is the fastest way to start a Spring app on Linux?

I have the following Spring program in a file titled calculator.java :

@RestController
public class Calculator {

    @RequestMapping("/calculate")
    public int calculate(@RequestParam("expression") String expression) {
        // parse the expression
        int result = 0;
        String[] tokens = expression.split("(\\+|-|\\*|/)");
        for (String token : tokens) {
            result += Integer.parseInt(token);
        }
        // return the result
        return result;
    }
}

I already tried starting it using spring run (I have Spring installed) but it does not work. The documentation is super confusing, what do I need to objectively do to start this calculator.java file with an endpoint accessible in "/calculate" from the browser?

Thank you.

Step 1 : Check out what the Linux domain or IP.

Step 2 : Check out what the tomcat start port and context path.

Step 3 : Open you browser input

http://{linux domain or IP}:{tomcat started port}/{context path}/calculate?expression=test

Example:

http://127.0.0.1:8080/test/calculate?expression=test

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM