Reputation: 87
I have developed a web service which I am trying to deploy to Heroku. It seems successful though whenever I try to call one of my URL's I get a 404. I know it means that the resource is not available but it works fine on localhost.
The output from the Heroku deployment is the standard Spring boot but it is missing the:
2016-05-23 22:29:22.145 INFO 15785 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/home],methods=[GET]}" onto public org.springframework.http.ResponseEntity<java.util.List<entity.Giver>> controller.GiverController.getHomeContent(javax.servlet.http.HttpServletRequest)
lines I normally get from running the app on localhost (the output is just one of the many I have).
I have a suspicion that when Heroku boots my app the annotation mappings does not get "compiled" since it does not get printed in the logs but I am just guessing.
My Procfile:
web: java $JAVA_OPTS -Dserver.port=$PORT -jar target/hams-x-jar-with-dependencies.jar
This is my dependencies and plugins from my pom.xml file (I excluded packaging etc since they should not be important):
<properties>
<java.version>1.8</java.version>
<spring.boot.version>1.3.3.RELEASE</spring.boot.version> <!--Variable-->
<tomcat.version>8.0.32</tomcat.version>
</properties>
<!--
Allows versioning and not to use the parent tag for spring boot framework
-->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>${spring.boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4.1207</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-hibernate5</artifactId>
<version>2.7.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
</plugin>
<plugin>
<groupId>com.heroku.sdk</groupId>
<artifactId>heroku-maven-plugin</artifactId>
<version>1.0.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<mainClass>controller.Application</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>controller.Application</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
The controllers are using @RestController as well as the @RequestMapping annotation for the path:
@RestController
public class GiverController {
@RequestMapping(value = "/home", method = RequestMethod.GET)
public ResponseEntity<List<Giver>> getHomeContent(HttpServletRequest request) {
List<Giver> homepageContent = GiverAPI.getHomePageContent();
if (homepageContent == null) {
return new ResponseEntity<List<Giver>>(HttpStatus.INTERNAL_SERVER_ERROR);
}
return new ResponseEntity<List<Giver>>(homepageContent, HttpStatus.OK);
}
}
The app is a Maven project containing a TomCat servlet with Spring Boot which package everything into a .jar file.
The Heroku CLI command I use for deployment is:
mvn clean heroku:deploy
I hope someone can help me.
Upvotes: 4
Views: 2720
Reputation: 48133
The spring-boot-starter-parent
POM includes <executions>
configuration to bind the repackage
goal. If you are not using the parent POM you will need to declare this configuration yourself. So, remove the maven-assembly-plugin
and maven-jar-plugin
plugin definitions and use the following:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
<configuration>
<mainClass>controller.Application</mainClass>
<layout>ZIP</layout>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
Also change the Procfile
and use the new jar
filename there. When you're not using the parent pom, this is the easiest way to create an executable jar. Checkout the Spring Boot documentation for more information.
Upvotes: 3