Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I deploy a Spring app to a production server?
    primarykey
    data
    text
    <p>I have a Spring MVC app built in Eclipse that I am trying to deploy as a war (to glassfish). I have an Application class that looks like this:</p> <pre><code>package com.jp5.rest; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.context.annotation.ComponentScan; import org.springframework.stereotype.Service; @Service @ComponentScan @EnableAutoConfiguration public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } public static void init() { SpringApplication.run(Application.class); } } </code></pre> <p><strong>Edit:</strong> I am getting close. The war file now deploys. But, I can not get to any of the web services end points (they all return 404s) Now, I have a web.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt; &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"&gt; &lt;context-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt;/WEB-INF/application-context.xml&lt;/param-value&gt; &lt;/context-param&gt; &lt;listener&gt; &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt; &lt;/listener&gt; &lt;/web-app&gt; </code></pre> <p>And an application-context.xml like this:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt; &lt;bean id="application" class="com.jp5.rest.Application" init-method="init" &gt; &lt;/bean&gt; &lt;context:component-scan base-package="com.jp5.rest"/&gt; &lt;/beans&gt; </code></pre> <p>The controller looks something like this:</p> <pre><code>package com.jp5.rest; @ComponentScan @EnableAutoConfiguration @Controller @RequestMapping("/jp5/rest/message") public class MessageRestService { @RequestMapping(method=RequestMethod.PUT, value="/test") public @ResponseBody testResult test() { return new testResult(true, "test"); } } </code></pre> <p><strong>Edit 2</strong> Thanks for the pointers. The solution from here: <a href="http://spring.io/guides/gs/convert-jar-to-war/" rel="nofollow">http://spring.io/guides/gs/convert-jar-to-war/</a> was to add a class like this. I have not tested yet, but, I think this can take the place of the web.xml:</p> <pre><code>package com.jp5.rest; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.SpringBootServletInitializer; public class Jp5RestXML extends SpringBootServletInitializer { @Override protected void configure(SpringApplicationBuilder application) { application.sources(Application.class); } } </code></pre> <p>thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload