So I am new to Spring - so I thought I would try Spring Boot
I am using a Maven to build - I set up a view requests, when I run it as \"App\" looks like it starts t
Below code worked fine for tomcat8 deployment without tomcat dependency.
@SpringBootApplication
@EnableAutoConfiguration
@ComponentScan
public class ManufacturingRegionApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
new SpringApplicationBuilder(ManufacturingRegionApplication.class).application().run(args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder applicationBuilder) {
return applicationBuilder.sources(application);
}
private static Class<ManufacturingRegionApplication> application = ManufacturingRegionApplication.class;
}
Below dependency is not required.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
@RestController
@RequestMapping(value = "/manufacturing-region-service")
public class ManufacturingRegionService {
@Resource
private ManufacturingRegionDao manufacturingRegionDao;
@ResponseBody
@Transactional(readOnly = true)
@RequestMapping(value = "/region-codes/{abbr}", method = GET, produces = "application/json")
http://localhost:8080/manufacturing-region-api/manufacturing-region-service/region-codes/ABBRVALUE
The chapter Packaging executable jar and war files in the Spring Boot reference documentation states:
To build a war file that is both executable and deployable into an external container you need to mark the embedded container dependencies as “provided”, e.g:
<?xml version="1.0" encoding="UTF-8"?>
<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">
<!-- ... -->
<packaging>war</packaging>
<!-- ... -->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<!-- ... -->
</dependencies>
</project>
When we choose Spring Boot, we don't want to produce a WAR. From the root page:
Spring Boot makes it easy to create stand-alone [...]
Applications that can you can "just run".
Embed Tomcat or Jetty directly (no need to deploy WAR files)
EDITED: So, if the purpose is "to try Spring Boot", I suggest to not generate a WAR file.
If you really need to produce a WAR file (keep your code built against SpringBoot and produce a file that you can run in any standard servlet container...) then you should read the documentation Converting a Spring Boot JAR Application to a WAR.
Did you include spring-boot-maven-plugin in the build process? You didn't describe this step...