java - Cannot access spring boot application after deployment in tomcat -
i have created rest api using spring boot. using gradle build tool. have tested application using embedded container , working fine. able access application @ localhost:8080/foo/bar
.
now have deployed tomcat without error.
mar 17, 2016 1:58:47 pm org.apache.catalina.startup.hostconfig deploywar info: deploying web application archive /usr/local/apache-tomcat-7.0.65/webapps/foo.war mar 17, 2016 1:58:48 pm org.apache.catalina.startup.tldconfig execute info: @ least 1 jar scanned tlds yet contained no tlds. enable debug logging logger complete list of jars scanned no tlds found in them. skipping unneeded jars during scanning can improve startup time , jsp compilation time. mar 17, 2016 1:58:48 pm org.apache.catalina.startup.hostconfig deploywar info: deployment of web application archive /usr/local/apache-tomcat-7.0.65/webapps/foo.war has finished in 623 ms
but unable access application @ localhost:8080/foo/bar
. can see tomcat running @ localhost:8080
here build.gradle
file.
buildscript { repositories { mavencentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.3.release") } } apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'spring-boot' apply plugin: 'war' war { basename = 'foo' } repositories { mavencentral() } sourcecompatibility = 1.8 targetcompatibility = 1.8 configurations{ providedruntime } dependencies { compile 'org.springframework.boot:spring-boot-starter-web' providedruntime("org.springframework.boot:spring-boot-starter-tomcat") compile 'com.google.code.gson:gson:2.6.2' compile 'org.springframework:spring-webmvc:4.2.5.release' compile 'org.json:json:20151123' providedruntime 'javax.ws.rs:javax.ws.rs-api:2.0.1' providedruntime 'javax.servlet:javax.servlet-api:3.1.0' providedruntime 'javax.servlet:jstl:1.2' testcompile("junit:junit") } task wrapper(type: wrapper) { gradleversion = '2.11' }
i have application.properties
file following code
server.context-path=/foo
and request mapping in controller set
@crossorigin @requestmapping("/bar") public string bar(){ // code }
i tried mentioned in post, not working.
@springbootapplication public class fooapplication { public static void main(string[] args) { springapplication.run(fooapplication.class, args); } // used when deploying standalone servlet container protected springapplicationbuilder configure(springapplicationbuilder application) { return application.sources(fooapplication.class); } }
to deploy spring boot application have have configuration class extends org.springframework.boot.context.web.springbootservletinitializer
, overrides org.springframework.boot.context.web.springbootservletinitializer.configure(springapplicationbuilder application)
so when application deployed in jee servlet container spring boot application deployed , served properly.
example
@configuration public class appservletinitializer extends springbootservletinitializer { @override protected springapplicationbuilder configure(springapplicationbuilder application) { return application.sources(application.class); } }
the application.class
same class in springapplication.run(application.class, args);
in main method
Comments
Post a Comment