I got a Spring Boot app. It's running as such:
#SpringBootApplication
public class MyBooty implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(MyBooty.class, args);
}
public void run(String... args) throws Exception {
SomeClass someClass = new SomeClass(...);
someClass.doStuff();
System.out.println("Why Am I appearing Before \"Started In\" log line?");
}
Does what I need. But I noticed this line in the output: Started MyBooty in 17.594 seconds (JVM running for 18.206), which was printed after some of my console output.
This made me think my code was actually executing before the app was actually initialized. So I did some research found this blog post and then set up a new class as such:
#Component
public class ApplicationStartup implements ApplicationListener<ApplicationReadyEvent>{
public void onApplicationEvent(ApplicationReadyEvent event) {
SomeClass someClass = new SomeClass(...);
SomeClass.doStuff();
return;
}
}
Which supposedly executes after after application startup. Well, I still see the Started app in... output after my output again.
So, concept check. Are things working as intended and I'm just being naive? Or is there maybe something missing? If someone could knowledge share on the topic that would be appreciated.
Again, my code runs and does exactly what I need it to, but I just want to make sure I'm using/taking advantage of Spring Boot properly.
In case it's unclear what I'm asking, I'm asking Why does the "Started App in X seconds" message appear after my output? I ask this because I simply found it confusing that it said the app was started after my business code had ALREADY ran. This question is a conceptual question about how spring boot starts up.
Edit: Console Output
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.3.2.RELEASE)
2016-09-23 17:44:56.598 INFO 1004 --- [ main] o.b.p.MyBooty : Starting MyBooty on ********* with PID **** (C:\...\MyBooty)
:
:
:
2016-09-23 17:44:59.152 INFO 1004 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2016-09-23 17:44:59.154 INFO 1004 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.0.30
2016-09-23 17:44:59.725 INFO 1004 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2016-09-23 17:44:59.725 INFO 1004 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3074 ms
2016-09-23 17:45:00.228 INFO 1004 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2016-09-23 17:45:00.234 INFO 1004 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2016-09-23 17:45:00.234 INFO 1004 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2016-09-23 17:45:00.234 INFO 1004 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2016-09-23 17:45:00.234 INFO 1004 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2016-09-23 17:45:00.824 INFO 1004 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for #ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#453da22c: startup date [Fri Sep 23 17:44:56 CDT 2016]; root of context hierarchy
2016-09-23 17:45:00.901 INFO 1004 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2016-09-23 17:45:00.902 INFO 1004 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2016-09-23 17:45:00.925 INFO 1004 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-09-23 17:45:00.925 INFO 1004 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-09-23 17:45:00.962 INFO 1004 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-09-23 17:45:01.136 INFO 1004 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2016-09-23 17:45:01.215 INFO 1004 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
Why Am I appearing Before "Started In" log line?
2016-09-23 17:45:17.063 INFO 1004 --- [ main] o.b.p.MyBooty : Started MyBooty in 20.814 seconds (JVM running for 23.279) <----- Why is this after my output?
2016-09-23 17:45:22.675 INFO 1004 --- [)-10.168.50.106] inMXBeanRegistrar$SpringApplicationAdmin : Application shutdown requested.
2016-09-23 17:45:22.676 INFO 1004 --- [)-10.168.50.106] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#453da22c: startup date [Fri Sep 23 17:44:56 CDT 2016]; root of context hierarchy
2016-09-23 17:45:22.678 INFO 1004 --- [)-10.168.50.106] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
You class is annotated with #SpringBootApplication, which makes it automatically register as a Spring Bean.
The SpringApplication run(Object source, String... args) method you are calling ends up calling run(String... args).
The run() method calls the afterRefresh() method right before it logs the "Started ..." message, and afterRefresh() will call the run() method of any registered ApplicationRunner and CommandLineRunner beans.
Or, as the documentation says it:
If you need to run some specific code once the SpringApplication has started, you can implement the ApplicationRunner or CommandLineRunner interfaces. Both interfaces work in the same way and offer a single run method which will be called just before SpringApplication.run(…) completes.
Related
This a springboot Application. It run perfectly but did not get output (it shows me HTTP Status 404 error in browser)
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.exaample.demo</groupId>
<artifactId>SpringBootMaven</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Maven spring boot project</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
</project>
Springboot start Class
Main Method
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class WebMainMethod {
public static void main(String[] args) {
SpringApplication.run(WebMainMethod.class, args);
}
}
controller is loading after main class
**Rest Controller**
package com.example.demo.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
#RestController
public class HelloController {
#RequestMapping("/hello")
public String sayHi() {
return "Hi";
}
}
Url : http://localhost:8080/hello
output
Unable to reproduce problem.
This is not an answer, but I copied the 3 files from question, and built and ran code without problem. My console log is however a bit different, included below, and that's why I'm posting this as an answer.
Try doing a clean build. Maybe that will fix the problem.
Console Log
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.9.RELEASE)
2017-12-02 02:06:19.763 INFO 13268 --- [ main] com.example.demo.WebMainMethod : Starting WebMainMethod on XXXX with PID 13268 (C:\Users\XXXX\SpringBootMaven\target\classes started by Andreas in C:\Users\XXXX\SpringBootMaven)
2017-12-02 02:06:19.765 INFO 13268 --- [ main] com.example.demo.WebMainMethod : No active profile set, falling back to default profiles: default
2017-12-02 02:06:19.794 INFO 13268 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#4f51b3e0: startup date [Sat Dec 02 02:06:19 EST 2017]; root of context hierarchy
2017-12-02 02:06:20.631 INFO 13268 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2017-12-02 02:06:20.641 INFO 13268 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2017-12-02 02:06:20.642 INFO 13268 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.23
2017-12-02 02:06:20.751 INFO 13268 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2017-12-02 02:06:20.751 INFO 13268 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 959 ms
2017-12-02 02:06:20.824 INFO 13268 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2017-12-02 02:06:20.826 INFO 13268 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-12-02 02:06:20.827 INFO 13268 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-12-02 02:06:20.827 INFO 13268 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-12-02 02:06:20.827 INFO 13268 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2017-12-02 02:06:21.025 INFO 13268 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for #ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#4f51b3e0: startup date [Sat Dec 02 02:06:19 EST 2017]; root of context hierarchy
2017-12-02 02:06:21.071 INFO 13268 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/hello]}" onto public java.lang.String com.example.demo.controller.HelloController.sayHi()
2017-12-02 02:06:21.074 INFO 13268 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2017-12-02 02:06:21.074 INFO 13268 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2017-12-02 02:06:21.095 INFO 13268 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-12-02 02:06:21.095 INFO 13268 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-12-02 02:06:21.119 INFO 13268 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-12-02 02:06:21.195 INFO 13268 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2017-12-02 02:06:21.271 INFO 13268 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2017-12-02 02:06:21.273 INFO 13268 --- [ main] com.example.demo.WebMainMethod : Started WebMainMethod in 1.908 seconds (JVM running for 2.231)
2017-12-02 02:06:38.426 INFO 13268 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2017-12-02 02:06:38.426 INFO 13268 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
2017-12-02 02:06:38.435 INFO 13268 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 9 ms
Maybe your template doesn't exist. Please specify file name of template which map with the retured value. Check this example
#Controller
public class HelloWorldController {
#RequestMapping("/hello")
public String hello(Model model, #RequestParam(value="name", required=false, defaultValue="World") String name) {
String message="You just create Spring Boot Example successfully";
model.addAttribute("name", name);
model.addAttribute("message", message);
return "hello";
}
}
Found this from Spring Boot Maven Example Hello World
It's seems there is some problem at your port 8080.
please change port and try to restart your appliaction.
Example: Add below to your application.properties file
server.port = 8090
and then try hitting http://localhost:8090/hello
You can try this.
Using application.properties /yml
The most straightforward way of changing the context path is to set the property in the application.properties:
server.servlet.context-path=/demoApp
Instead of putting the properties file in src/main/resources, we can also keep it in the current working directory (outside of the classpath).
Java System Property.
http://localhost:8090/demoApp/hello
for more info.
https://www.baeldung.com/spring-boot-context-path
Do you create a jsp or html page called hi... Check your views... You don;t have page to view.... Please create a jsp and put it on
#RequestMapping("/hello")
public String sayHi(Model model) {
model.addAttribute("Hi","Hi")
return "Hi";
}
jsp page must be Hi
Spring boot issues with following code. see error below and tomcat is running fine
package com.template;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class SpringBootFreemarkerApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootFreemarkerApplication.class,
args);
}
}
package controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
#Controller
public class TestController {
#RequestMapping("/welcome")
public String hello(Model model, #RequestParam(value="name",
required=false, defaultValue="World") String name) {
model.addAttribute("name", name);
return "welcome";
}
}
"C:\Program Files\Java\jdk1.8.0_121\bin\java" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2017.1.5\lib\idea_rt.jar=54267:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2017.1.5\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_121\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar;C:\SpringBoot\Spring-boot-freemarker\target\classes;C:\Users\shekhar\.m2\repository\org\springframework\boot\spring-boot-starter-freemarker\1.5.6.RELEASE\spring-boot-starter-freemarker-1.5.6.RELEASE.jar;C:\Users\shekhar\.m2\repository\org\springframework\boot\spring-boot-starter\1.5.6.RELEASE\spring-boot-starter-1.5.6.RELEASE.jar;C:\Users\shekhar\.m2\repository\org\springframework\boot\spring-boot\1.5.6.RELEASE\spring-boot-1.5.6.RELEASE.jar;C:\Users\shekhar\.m2\repository\org\springframework\boot\spring-boot-autoconfigure\1.5.6.RELEASE\spring-boot-autoconfigure-1.5.6.RELEASE.jar;C:\Users\shekhar\.m2\repository\org\springframework\boot\spring-boot-starter-logging\1.5.6.RELEASE\spring-boot-starter-logging-1.5.6.RELEASE.jar;C:\Users\shekhar\.m2\repository\ch\qos\logback\logback-classic\1.1.11\logback-classic-1.1.11.jar;C:\Users\shekhar\.m2\repository\ch\qos\logback\logback-core\1.1.11\logback-core-1.1.11.jar;C:\Users\shekhar\.m2\repository\org\slf4j\jcl-over-slf4j\1.7.25\jcl-over-slf4j-1.7.25.jar;C:\Users\shekhar\.m2\repository\org\slf4j\jul-to-slf4j\1.7.25\jul-to-slf4j-1.7.25.jar;C:\Users\shekhar\.m2\repository\org\slf4j\log4j-over-slf4j\1.7.25\log4j-over-slf4j-1.7.25.jar;C:\Users\shekhar\.m2\repository\org\yaml\snakeyaml\1.17\snakeyaml-1.17.jar;C:\Users\shekhar\.m2\repository\org\freemarker\freemarker\2.3.26-incubating\freemarker-2.3.26-incubating.jar;C:\Users\shekhar\.m2\repository\org\springframework\spring-context-support\4.3.10.RELEASE\spring-context-support-4.3.10.RELEASE.jar;C:\Users\shekhar\.m2\repository\org\springframework\spring-beans\4.3.10.RELEASE\spring-beans-4.3.10.RELEASE.jar;C:\Users\shekhar\.m2\repository\org\springframework\spring-context\4.3.10.RELEASE\spring-context-4.3.10.RELEASE.jar;C:\Users\shekhar\.m2\repository\org\springframework\boot\spring-boot-starter-web\1.5.6.RELEASE\spring-boot-starter-web-1.5.6.RELEASE.jar;C:\Users\shekhar\.m2\repository\org\springframework\boot\spring-boot-starter-tomcat\1.5.6.RELEASE\spring-boot-starter-tomcat-1.5.6.RELEASE.jar;C:\Users\shekhar\.m2\repository\org\apache\tomcat\embed\tomcat-embed-core\8.5.16\tomcat-embed-core-8.5.16.jar;C:\Users\shekhar\.m2\repository\org\apache\tomcat\embed\tomcat-embed-el\8.5.16\tomcat-embed-el-8.5.16.jar;C:\Users\shekhar\.m2\repository\org\apache\tomcat\embed\tomcat-embed-websocket\8.5.16\tomcat-embed-websocket-8.5.16.jar;C:\Users\shekhar\.m2\repository\org\hibernate\hibernate-validator\5.3.5.Final\hibernate-validator-5.3.5.Final.jar;C:\Users\shekhar\.m2\repository\javax\validation\validation-api\1.1.0.Final\validation-api-1.1.0.Final.jar;C:\Users\shekhar\.m2\repository\org\jboss\logging\jboss-logging\3.3.1.Final\jboss-logging-3.3.1.Final.jar;C:\Users\shekhar\.m2\repository\com\fasterxml\classmate\1.3.3\classmate-1.3.3.jar;C:\Users\shekhar\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.8.9\jackson-databind-2.8.9.jar;C:\Users\shekhar\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.8.0\jackson-annotations-2.8.0.jar;C:\Users\shekhar\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.8.9\jackson-core-2.8.9.jar;C:\Users\shekhar\.m2\repository\org\springframework\spring-web\4.3.10.RELEASE\spring-web-4.3.10.RELEASE.jar;C:\Users\shekhar\.m2\repository\org\springframework\spring-aop\4.3.10.RELEASE\spring-aop-4.3.10.RELEASE.jar;C:\Users\shekhar\.m2\repository\org\springframework\spring-webmvc\4.3.10.RELEASE\spring-webmvc-4.3.10.RELEASE.jar;C:\Users\shekhar\.m2\repository\org\springframework\spring-expression\4.3.10.RELEASE\spring-expression-4.3.10.RELEASE.jar;C:\Users\shekhar\.m2\repository\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;C:\Users\shekhar\.m2\repository\org\springframework\spring-core\4.3.10.RELEASE\spring-core-4.3.10.RELEASE.jar" com.template.SpringBootFreemarkerApplication
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.6.RELEASE)
2017-07-30 15:20:08.005 INFO 7612 --- [ main] c.t.SpringBootFreemarkerApplication : Starting SpringBootFreemarkerApplication on DESKTOP-9LIAED5 with PID 7612 (C:\SpringBoot\Spring-boot-freemarker\target\classes started by shekhar in C:\SpringBoot\Spring-boot-freemarker)
2017-07-30 15:20:08.008 INFO 7612 --- [ main] c.t.SpringBootFreemarkerApplication : No active profile set, falling back to default profiles: default
2017-07-30 15:20:08.074 INFO 7612 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#3bd94634: startup date [Sun Jul 30 15:20:08 IST 2017]; root of context hierarchy
2017-07-30 15:20:10.322 INFO 7612 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2017-07-30 15:20:10.333 INFO 7612 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2017-07-30 15:20:10.334 INFO 7612 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.16
2017-07-30 15:20:10.472 INFO 7612 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2017-07-30 15:20:10.472 INFO 7612 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2398 ms
2017-07-30 15:20:10.788 INFO 7612 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2017-07-30 15:20:10.792 INFO 7612 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-07-30 15:20:10.792 INFO 7612 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-07-30 15:20:10.793 INFO 7612 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-07-30 15:20:10.793 INFO 7612 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2017-07-30 15:20:11.221 INFO 7612 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for #ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#3bd94634: startup date [Sun Jul 30 15:20:08 IST 2017]; root of context hierarchy
2017-07-30 15:20:11.299 INFO 7612 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/welcome]}" onto public java.lang.String com.template.controller.TestController.hello(org.springframework.ui.Model,java.lang.String)
2017-07-30 15:20:11.302 INFO 7612 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2017-07-30 15:20:11.302 INFO 7612 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2017-07-30 15:20:11.337 INFO 7612 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-07-30 15:20:11.337 INFO 7612 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-07-30 15:20:11.374 INFO 7612 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-07-30 15:20:11.626 INFO 7612 --- [ main] o.s.w.s.v.f.FreeMarkerConfigurer : ClassTemplateLoader for Spring macros added to FreeMarker configuration
2017-07-30 15:20:11.727 INFO 7612 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2017-07-30 15:20:11.790 INFO 7612 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2017-07-30 15:20:11.795 INFO 7612 --- [ main] c.t.SpringBootFreemarkerApplication : Started SpringBootFreemarkerApplication in 4.222 seconds (JVM running for 5.046)
Your controller is not scanned by the default component scan that Spring Boot provides. By default Spring boot starts from the package that contains the "main" class - the one annotated with #SpringBootApplication and also scans all of it's sub packages.
Your main class is in package com.template; but the controller is in package controller;. Move the controller in a package named package com.template.controller;
Since you are using FreeMarker Template with spring boot, I would suggest you to move your welcome.ftl template from this location src/webapp/welcome.ftl to this src/main/resources/templates/welcome.ftl and then restart your application and hit http://localhost:8080/welcome
I have a JUnit Test that starts my spring boot appcliation (Application.java).
#RunWith(SpringRunner.class)
#SpringBootTest(classes = Application.class)
public class AppclaitionTest {
#Test
public void contextLoads(){
Application.main(new String[]{});
}
}
If I run the JUnit test, Application is successfully starting up, but not accessible through url
Application Logs:
2017-06-16 12:18:07.918 INFO 207028 --- [ main] com.chandu.test.AppclaitionTest : Started AppclaitionTest in 1.927 seconds (JVM running for 2.458)
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.3.RELEASE)
2017-06-16 12:18:08.012 INFO 207028 --- [ main] com.test.app.Application : Starting Application on IVL-WS39 with PID 207028 (started by Bhanuchandar.Challa in D:\Jars\SpringJDBCMySQL)
2017-06-16 12:18:08.012 INFO 207028 --- [ main] com.test.app.Application : No active profile set, falling back to default profiles: default
2017-06-16 12:18:08.012 INFO 207028 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#3f1ddac2: startup date [Fri Jun 16 12:18:08 IST 2017]; root of context hierarchy
2017-06-16 12:18:08.402 INFO 207028 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2017-06-16 12:18:08.417 INFO 207028 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2017-06-16 12:18:08.417 INFO 207028 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.14
2017-06-16 12:18:08.526 INFO 207028 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2017-06-16 12:18:08.526 INFO 207028 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 514 ms
2017-06-16 12:18:08.636 INFO 207028 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2017-06-16 12:18:08.636 INFO 207028 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-06-16 12:18:08.636 INFO 207028 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-06-16 12:18:08.636 INFO 207028 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-06-16 12:18:08.636 INFO 207028 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2017-06-16 12:18:08.933 INFO 207028 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for #ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#3f1ddac2: startup date [Fri Jun 16 12:18:08 IST 2017]; root of context hierarchy
2017-06-16 12:18:08.933 INFO 207028 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/getRowCount]}" onto public java.lang.Integer com.test.app.controller.TestController.getRowCount(java.lang.String)
2017-06-16 12:18:08.949 INFO 207028 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/process]}" onto public java.lang.String com.test.app.controller.TestController.processRequest()
2017-06-16 12:18:08.949 INFO 207028 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2017-06-16 12:18:08.949 INFO 207028 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2017-06-16 12:18:08.964 INFO 207028 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-06-16 12:18:08.964 INFO 207028 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-06-16 12:18:08.980 INFO 207028 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-06-16 12:18:09.105 INFO 207028 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2017-06-16 12:18:09.151 INFO 207028 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2017-06-16 12:18:09.151 INFO 207028 --- [ main] com.test.app.Application : Started Application in 1.186 seconds (JVM running for 3.689)
When I tried to access the application through url 'http://localhost:8080/process', It says Site can't be reached.
Why would you do such thing? This should be a unit test and the flow of the test should be the following:
Start the application -> Call your controller endpoint -> assert that a specific text/element on that page is present -> Shut down the application.
Start the application : #RunWith(SpringRunner.class) doing this for you, no need to start is manually.
Shut down the application : At the end of your test class Spring boot does this for you (That's why you cant access your app in the browser)
For further help please see my answer here: How to test (rest) enpoints
By default, in #SpringBootTest annotation the field webEnvironment is set to WebEnvironment.MOCK
Therefore, Tomcat does not start.
You can set this field to WebEnvironment.DEFINED_PORT/RANDOM_PORT.
After this, Tomcat will be running.
#SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class MyTestClass {
...
...
...
}
I'm trying to use the spring framework for the first time. Unfortunately I'm getting 404-error when I call the URL of my webservice. Tomcat deployment of the war file is working (no errors in the logs).
When I execute the Example.java in eclipse everythings works fine.
Where is the mistake?
See my files/logs:
Example.java
import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.*;
#Controller
#EnableAutoConfiguration
public class Example {
#RequestMapping("/")
#ResponseBody
String home() {
return "Hello World!";
}
public static void main(String[] args) throws Exception {
SpringApplication.run(Example.class, args);
}
}
build.gradle
buildscript {
repositories {
jcenter()
maven { url 'http://repo.spring.io/snapshot' }
maven { url 'http://repo.spring.io/milestone' }
}
dependencies {
classpath 'org.springframework.boot:spring-boot-gradle-plugin:2.0.0.BUILD-SNAPSHOT'
}
}
task wrapper(type: Wrapper) {
gradleVersion = '3.5'
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
jar {
baseName = 'myproject'
version = '0.0.1-SNAPSHOT'
}
repositories {
jcenter()
maven { url "http://repo.spring.io/snapshot" }
maven { url "http://repo.spring.io/milestone" }
}
dependencies {
//compile 'org.slf4j:slf4j-api:1.7.21'
compile("org.springframework.boot:spring-boot-starter-web")
testCompile("org.springframework.boot:spring-boot-starter-test")
//testCompile 'junit:junit:4.12'
}
log when starting the application inside eclipse
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.0.BUILD-SNAPSHOT)
2017-06-01 16:22:17.745 INFO 14940 --- [ main] Example : Starting Example on Laptop-Timo with PID 14940 (started by Timo in C:\Users\Timo\Documents\SE\Semester 4\LabSW\Webservice\TimeShoppingService)
2017-06-01 16:22:17.745 INFO 14940 --- [ main] Example : No active profile set, falling back to default profiles: default
2017-06-01 16:22:17.815 INFO 14940 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#6a01e23: startup date [Thu Jun 01 16:22:17 CEST 2017]; root of context hierarchy
2017-06-01 16:22:20.098 INFO 14940 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2017-06-01 16:22:20.116 INFO 14940 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2017-06-01 16:22:20.116 INFO 14940 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.15
2017-06-01 16:22:20.264 INFO 14940 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2017-06-01 16:22:20.264 INFO 14940 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2449 ms
2017-06-01 16:22:20.626 INFO 14940 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2017-06-01 16:22:20.638 INFO 14940 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-06-01 16:22:20.639 INFO 14940 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-06-01 16:22:20.639 INFO 14940 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-06-01 16:22:20.640 INFO 14940 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2017-06-01 16:22:21.343 INFO 14940 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for #ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#6a01e23: startup date [Thu Jun 01 16:22:17 CEST 2017]; root of context hierarchy
2017-06-01 16:22:21.442 INFO 14940 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/]}" onto java.lang.String Example.home()
2017-06-01 16:22:21.456 INFO 14940 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2017-06-01 16:22:21.457 INFO 14940 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2017-06-01 16:22:21.548 INFO 14940 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-06-01 16:22:21.549 INFO 14940 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-06-01 16:22:21.683 INFO 14940 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-06-01 16:22:21.940 INFO 14940 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2017-06-01 16:22:22.018 INFO 14940 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http)
2017-06-01 16:22:22.024 INFO 14940 --- [ main] Example : Started Example in 4.81 seconds (JVM running for 5.487)
2017-06-01 16:22:32.727 INFO 14940 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2017-06-01 16:22:32.727 INFO 14940 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
2017-06-01 16:22:32.755 INFO 14940 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 28 ms
Use #RestController instead of #Controller and just give request like
localhost:8080/
In order to deploy a spring-boot application to an external servlet container you need to extend SpringBootServletInitializer.
The main method is only executed when the application is run standalone.
It is recommended to run spring-boot apps standalone rather than via an external servlet container, but it is possible to support both methods simultaneously.
See the spring documentation for more information.
By Default context path of Spring boot application is '/'. So in your case url to access home resource will be http://localhost:8080/
For custom context path add an application.properties file to src\main\resources. In that properties file, add 2 properties:
server.contextPath=/Service
server.port=12378
You may refer this link for example.
Maybe url mistake. try it like the url below .
http://localhost:8080/Service/
You have not mapped your controller or method with any specific string.
#Controller
#EnableAutoConfiguration
public class Example {
#RequestMapping("/")
#ResponseBody
String home() {
return "Hello World!";
}
...
You have used #RequestMapping("/") which maps the home() method so you need to use localhost:8080/ url instead of localhost:8080/service
and if you want to use the service in url just change mapping to #RequestMapping("/service").
The easiest way out is just by replacing the annotation above the class respectively. And use the #RestController, then you move the #RequestMapping("/") above the class, Beneath the rest controller. Go to the Postman and call it with localhost:8080/ and that's all
I would like to set up a dev environment on my Windows 7 machine so i can create a spring-boot application. However, i'm having a hard time installing Spring-boot on windows.
This is what i have done so far:
-Downloaded spring-boot CLI zip package and unzipped in C drive
-JAVA_HOME variable set to c:\Program Files (x86)\Java\jdk1.6.0_14
-SPRING_HOME variable set to C:\spring-1.3.0.BUILD-SNAPSHOT
-Added SPRING_HOME/bin to PATH environment variable
It says to add symlink to auto-completion script but i do not know how to do that. Not surprisingly when i test installation with "spring --version" command, it fails.
Anybody has done this before?
Thanks!
Instructions for setup are bit misleading for path setup.
For Windows, Environment variables section, need use %SPRING_HOME%\bin referencing in place of SPRING_HOME/bin for the system to pick up SPRING_HOME environment variable.
Where SPRING_HOME is an environment variable for specifying path to the spring boot directory.
E.g. :- C:\Program Files\Spring\spring-1.2.7.RELEASE
Note: bin folder is not included in the SPRING_HOME.
I was able to get it up, here are screen grabs of process.
Alternatively you can have the path setup directly without SPRING_HOME, just append the environment variable path with directory path of your "spring.bat" file C:\Program Files\Spring\spring-1.2.7.RELEASE\bin;.
Windows looks in the current directory before searching the path. So, when you're in the bin directory it sees the spring command there and does not look at the path.
1.MANUALLY INSTALLING THE SPRING BOOT CLI
spring-boot-cli-2.0.0.M1-bin.zip is installed.
2.Extract spring-boot-cli-2.0.0.M1-bin.zip.
3.After spring-2.0.0.M1 extractd.
4. Direct command prompt
--------------------------
C:\Users\nepl>spring --version
'spring' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\nepl>E:
E:\>cd Nagarjuna
E:\Nagarjuna>cd "spring applications"
E:\Nagarjuna\spring applications>cd spring-2.0.0.M1
E:\Nagarjuna\spring applications\spring-2.0.0.M1>cd bin
E:\Nagarjuna\spring applications\spring-2.0.0.M1\bin>spring -- version
'--' is not a valid command. See 'help'.
E:\Nagarjuna\spring applications\spring-2.0.0.M1\bin>spring --version
Spring CLI v2.0.0.M1
E:\Nagarjuna\spring applications\spring-2.0.0.M1\bin>spring --help
E:\Nagarjuna\spring applications\spring-2.0.0.M1\bin>spring run HelloWorld.groov
y
Resolving dependencies......................................................
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.0.M1)
2017-12-15 15:36:07.949 INFO 3464 --- [ runner-0] o.s.boot.SpringApplicat
ion : Starting application on nw0188 with PID 3464 (started by nep
l in E:\Nagarjuna\spring applications\spring-2.0.0.M1\bin)
2017-12-15 15:36:07.996 INFO 3464 --- [ runner-0] o.s.boot.SpringApplicat
ion : No active profile set, falling back to default profiles: def
ault
2017-12-15 15:36:08.689 INFO 3464 --- [ runner-0] ConfigServletWebServerA
pplicationContext : Refreshing org.springframework.boot.web.servlet.context.Anno
tationConfigServletWebServerApplicationContext#48cd5e87: startup date [Fri Dec 1
5 15:36:08 IST 2017]; root of context hierarchy
2017-12-15 15:36:11.575 INFO 3464 --- [ runner-0] o.s.b.w.embedded.tomcat
.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2017-12-15 15:36:11.606 INFO 3464 --- [ runner-0] o.apache.catalina.core.
StandardService : Starting service [Tomcat]
2017-12-15 15:36:11.606 INFO 3464 --- [ runner-0] org.apache.catalina.cor
e.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.15
2017-12-15 15:36:12.285 INFO 3464 --- [ost-startStop-1] org.apache.catalina.loa
der.WebappLoader : Unknown loader org.springframework.boot.cli.compiler.Extende
dGroovyClassLoader$DefaultScopeParentClassLoader#526a6c66 class org.springframew
ork.boot.cli.compiler.ExtendedGroovyClassLoader$DefaultScopeParentClassLoader
2017-12-15 15:36:12.378 INFO 3464 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[loc
alhost].[/] : Initializing Spring embedded WebApplicationContext
2017-12-15 15:36:12.378 INFO 3464 --- [ost-startStop-1] o.s.web.context.Context
Loader : Root WebApplicationContext: initialization completed in 3689
ms
2017-12-15 15:36:12.550 INFO 3464 --- [ost-startStop-1] o.s.b.w.servlet.Servlet
RegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2017-12-15 15:36:12.550 INFO 3464 --- [ost-startStop-1] o.s.b.w.servlet.FilterR
egistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-12-15 15:36:12.550 INFO 3464 --- [ost-startStop-1] o.s.b.w.servlet.FilterR
egistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-12-15 15:36:12.550 INFO 3464 --- [ost-startStop-1] o.s.b.w.servlet.FilterR
egistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-12-15 15:36:12.550 INFO 3464 --- [ost-startStop-1] o.s.b.w.servlet.FilterR
egistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2017-12-15 15:36:13.070 INFO 3464 --- [ runner-0] s.w.s.m.m.a.RequestMapp
ingHandlerAdapter : Looking for #ControllerAdvice: org.springframework.boot.web.
servlet.context.AnnotationConfigServletWebServerApplicationContext#48cd5e87: sta
rtup date [Fri Dec 15 15:36:08 IST 2017]; root of context hierarchy
2017-12-15 15:36:13.200 INFO 3464 --- [ runner-0] s.w.s.m.m.a.RequestMapp
ingHandlerMapping : Mapped "{[/]}" onto public java.util.Map HelloWorld.home()
2017-12-15 15:36:13.209 INFO 3464 --- [ runner-0] s.w.s.m.m.a.RequestMapp
ingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.Res
ponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframewo
rk.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet
.http.HttpServletRequest)
2017-12-15 15:36:13.209 INFO 3464 --- [ runner-0] s.w.s.m.m.a.RequestMapp
ingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.spr
ingframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web
.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequ
est,javax.servlet.http.HttpServletResponse)
2017-12-15 15:36:13.242 INFO 3464 --- [ runner-0] o.s.w.s.handler.SimpleU
rlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class or
g.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-12-15 15:36:13.242 INFO 3464 --- [ runner-0] o.s.w.s.handler.SimpleU
rlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.spring
framework.web.servlet.resource.ResourceHttpRequestHandler]
2017-12-15 15:36:13.289 INFO 3464 --- [ runner-0] o.s.w.s.handler.SimpleU
rlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [clas
s org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-12-15 15:36:13.976 INFO 3464 --- [ runner-0] o.s.j.e.a.AnnotationMBe
anExporter : Registering beans for JMX exposure on startup
2017-12-15 15:36:14.170 INFO 3464 --- [ runner-0] o.s.b.w.embedded.tomcat
.TomcatWebServer : Tomcat started on port(s): 8080 (http)
2017-12-15 15:36:14.175 INFO 3464 --- [ runner-0] o.s.boot.SpringApplicat
ion : Started application in 8.06 seconds (JVM running for 77.714)
2017-12-15 15:37:42.225 INFO 3464 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[loc
alhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2017-12-15 15:37:42.226 INFO 3464 --- [nio-8080-exec-1] o.s.web.servlet.Dispatc
herServlet : FrameworkServlet 'dispatcherServlet': initialization started
2017-12-15 15:37:42.249 INFO 3464 --- [nio-8080-exec-1] o.s.web.servlet.Dispatc
herServlet : FrameworkServlet 'dispatcherServlet': initialization complet
ed in 23 ms