converting spring boot jar to war - java

I developed a spring boot project. Now my requirement is to convert the jar package into war.
1. I converted the jar into war. After converting, I deployed the war into the tomcat server and tried to hit the web service.
#EnableAsync
#RestController
#EnableAutoConfiguration
#SpringBootApplication
#ComponentScan(basePackages="com.app.sensiple")
public class SensipleApplication extends SpringBootServletInitializer {
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(SensipleApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(SensipleApplication.class, args);
}
#RequestMapping("/test")
String test() {
return "This is test and it's Working fine!";
}
POM.xml
<?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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.app</groupId>
<artifactId>snservice</artifactId>
<version>443-async</version>
<packaging>war</packaging>
<name>sensiple</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<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>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20160810</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
UrL: localhost:8080/snservice/test
The above url is working fine.
My application contains different packages like Controller, Service and Repo. I have added the screenshot of my project structure.
The issue is i can't able to hit the services in controller package. Do i need to configure dispatcher Servlet for this???? . Anybody please help me out?

If you are using maven you can indicate it in pom.xml packaging
<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>
Next you need to provide a SpringBootServletInitializer subclass and override its configure method.
#SpringBootApplication
public class Application extends SpringBootServletInitializer {
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}

We need 3 steps for convert JAR to WAR in Spring Boot:
Change packaging to war
Marked the embedded tomcat as provided.
Extends SpringBootServletInitializer and override the configure()
method.
I have converted jar to war in spring boot by using given below website (Explained step by step).
https://tecmentor.in/spring-boot/convert-jar-to-war-in-spring-boot/

Related

Spring Boot returns Error 404 even though mapping has been set

I downloaded a Spring Boot project from Spring Initializr. I am trying to call sayHello() method in DemoApplication.java. Here are my code.
DemoApplication.java
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
#SpringBootApplication
#RestController
public class DemoApplication {
public static void main(String[] args) {
System.out.println("started");
SpringApplication.run(DemoApplication.class, args);
System.out.println("Success");
}
#GetMapping("/hello")
public String sayHello(#RequestParam(value = "myName", defaultValue = "World") String name) {
return String.format("Hello %s!", name);
}
}
pom.xml
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.3.6</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<!--<scope>provided</scope>-->
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
When I run on http://localhost:8080/hello it returns error 404 page. It does not call sayHello() method even though I have set the GET mapping. What could be the issue?
The problem is your dependencies, or rather the lack of them.
You included spring-web as a dependency but that isn't enough to launch your web app. You would also need to add spring-webmvc and as you want to use REST (and probably JSON) you would need to add the jackson-databind dependency (and if you want to support dates also the jackson-datatype-jdk8 dependency).
Now you could of course manually figure all this out yourself by trial and error. Or you just include the spring-boot-starter-web which automatically includes (compatible) versions of all of those dependencies (including Embedded Tomcat).
So in short fix your dependencies.
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
This should be all you need, if you build a WAR instead of JAR you might want to add
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
This will make tomcat provided and moved out of the lib folder but still your app would be runnable for development (through the main method) and deployable as a war (without tomcat being in the lib directory).

Not able to access application on Tomcat with Swagger, Spring, Hibernate

I am using Swagger-UI and Codegen to generate my APIs and then I am using Spring Boot and Hibernate in my application.
When I build my application and run via Maven command mvn spring-boot:run, my application runs and Swagger UI is displayed. But when I create the WAR file and deploy it to Tomcat server, I am not able to access the application. I do not see any errors in Catalina logs. Any advice on what could be going wrong?
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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.datadivers</groupId>
<artifactId>swagger-spring</artifactId>
<packaging>war</packaging>
<name>swagger-spring</name>
<version>1.0.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.5</version>
</parent>
<properties>
<java.version>1.8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<springfox-version>2.9.2</springfox-version>
</properties>
<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>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--SpringFox dependencies -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${springfox-version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox-version}</version>
</dependency>
<dependency>
<groupId>com.github.joschi.jackson</groupId>
<artifactId>jackson-datatype-threetenbp</artifactId>
<version>2.6.4</version>
</dependency>
<!-- Bean Validation API support -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<finalName>bankingapi</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.5.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Spring Boot application:
imports...
#SpringBootApplication
#EnableSwagger2
#EnableJpaRepositories(basePackages = "com.datadivers.repository")
#EntityScan(basePackages = "com.datadivers.model")
#ComponentScan(basePackages = { "io.swagger", "io.swagger.configuration", "com.datadivers.api", "com.datadivers.service"})
public class Swagger2SpringBoot extends SpringBootServletInitializer{
public static void main(String[] args) {
SpringApplication.run(Swagger2SpringBoot.class, args);
}
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Swagger2SpringBoot.class);
}
}
The suggestion from #PiotrP.Karwasz worked for me. Hence submitting this as the answer to my problem. Thank you for the help.
Spring 5 requires a Java EE 8 server (it provides a
javax.servlet.ServletContainerInitializer), while Tomcat 10 is a
Jakarta EE 9 server (it searches for a
jakarta.servlet.ServletContainerInitializer): see this question.
Downgrade to Tomcat 9.0 and it should work.
In Intellij idea
in project structure, you can create artifacts
pay attention to output directory this path must be excluded in Module section
now you can add war file to Deployment Section in Configuration Section
if you have security checked the access when input url swagger in to browser
Try this guideline https://www.baeldung.com/spring-boot-war-tomcat-deploy#creating-a-spring-boot-war
add a Tomcat dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
and add SpringBootServletInitializer
like in example
#SpringBootApplication
public class SpringBootTomcatApplication extends SpringBootServletInitializer {
}

Deploy Spring App to Tomcat without web.xml

I have successfully tested my war file with embedded TOMCAT and it works fine. Now I want to deploy it to TOMCAT but I keep getting a 404 error.
The URL I navigate to on the browser is
http://localhost:9999/springrest/demo/users/all
My TOMCAT uses the port 9999
My JRE_HOME version is 1.8.0_261
My pom.xml has <java.version>1.8</java.version>
TOMCAT manager shows the app as running
My Controller code is as follows
#RestController
#RequestMapping(path="/demo")
public class UserController {
#Autowired
private UserRepository userRepository;
#GetMapping(path="/users/all")
public #ResponseBody Iterable<User> getAllUsers() {
// This returns a JSON or XML with the users
return userRepository.findAll();
}
}
My pom.xml
<?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
https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<relativePath/>
</parent>
<groupId>com.eptc</groupId>
<artifactId>springrest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springrest</name>
<description>Rest API for mobile app</description>
<packaging>war</packaging>
<properties>
<java.version>1.8</java.version>
<start-class>com.eptc.springrest.SpringrestApplication</start-class>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.6.2</version>
<scope>test</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>${artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Have you initialized the Servlet context required by Tomcat by implementing the SpringBootServletInitializer interface?
#SpringBootApplication
public class SpringBootTomcatApplication extends SpringBootServletInitializer {
}
Please refer this link for the details :Deploy a Spring Boot WAR into a Tomcat Server
Changed my Apache Tomcat version to Apache Tomcat 8.5.58 and it worked like a charm.
The Springboot banner even shows on cmd on running catalina.bat run

How to run Spring app on localhost without IntelliJ?

My app works when run from IntelliJ but I have issues trying to run it without help of IntelliJ.
Main class:
#SpringBootApplication
public class LoadingsApplication {
public static void main(String[] args) {
SpringApplication.run(LoadingsApplication.class, args);
}
}
pom.xml:
<?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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>pl.margol</groupId>
<artifactId>loadings</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>loadings</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.8.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
application.properties:
server.port=8087
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
# H2
spring.h2.console.enabled=true
spring.h2.console.path=/h2
# Datasource
spring.datasource.url=jdbc:h2:file:~/loadings-db;
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driver-class-name=org.h2.Driver
spring.jpa.hibernate.ddl-auto=update
.war file was created and deployed in Tomcat Web Application Manager.
When I call localhost:8080/loadings-0.0.1-SNAPSHOT/start
i get error:
HTTP Status 404 – Not Found
Type Status Report
Message /loadings-0.0.1-SNAPSHOT/start
Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
Apache Tomcat/9.0.20
I was trying to change port in application.properties file but it didn't help.
Can You help to solve this problem?
I think your application didn't deployed at all.
Since you are deploying your application as war file in external container you will need to extend SpringBootServletInitializer.
Your class will look like this:
#SpringBootApplication
public class LoadingApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(HelloServerApplication.class, args);
}
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder)
{
return builder.sources(HelloServerApplication.class);
}
}
Why are you using this dependency:
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
You don't need it or mark it's scope as provided
Also you may need to exclude tomcat from spring-boot-starter-weblike this:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
And Since you are using external container server.port=8087 will not work.
Try this.
#SpringBootApplication
public class LoadingsApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(LoadingsApplication.class, args);
}
}

Spring boot how to make project run on server in eclipse

I am new to Spring Boot, I have sample spring boot code in my Eclipse
IDE.
Now to run the project. In project there is class "Application", I run
that using Run As Java Application and then Its running on given port.
But I want it to run using Run on Server option of Eclipse, so
whenever I try to run that on server it gives me 404.
Please give me any idea to resolve this issue.
Code:
#ComponentScan
#Configuration
#EnableAutoConfiguration
public class Application extends SpringBootServletInitializer {
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) {
ApplicationContext ctx = SpringApplication.run(Application.class, args);
System.out.println("Let's inspect the beans provided by Spring Boot:");
String[] beanNames = ctx.getBeanDefinitionNames();
Arrays.sort(beanNames);
System.out.println(Arrays.toString(beanNames));
}
}
application.properties
server.address=localhost
server.port=8080
server.contextPath=/spring-security-cas
app.service.security=http://localhost:8080/j_spring_cas_security_check
app.service.home=http://localhost:8080/
pom.xml
<?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">
<modelVersion>4.0.0</modelVersion>
<groupId>org.esco.demo</groupId>
<artifactId>spring-security-cas</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>demo-spring-security-cas</name>
<description>Demo project for Spring Boot</description>
<parent>
<artifactId>spring-boot-starter-parent</artifactId>
<groupId>org.springframework.boot</groupId>
<version>1.2.1.RELEASE</version>
<relativePath />
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-cas</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
</dependency>
<!-- Usefull for accessing to jsp -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<!-- END Usefull for accessing to jsp -->
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.14.8</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<start-class>org.esco.demo.ssc.Application</start-class>
<java.version>1.7</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Note: Project running when run Application as Run as Java Application,
problem is I want it to run using Run on Server option.
If you want to deploy it to a container, instead of using the embedded container follow this section in the reference guide.
In short the steps are
Use war packaging instead of jar packaging
Let your Application class extends SpringBootServletInitializer and implement the configure method.
Mark the container dependencies (tomcat I guess) as provided
So in a nutshell
Change <packaging>jar</packaging> to <packaging>war</packaging>
Change your Application
public class Application extends SpringBootServletInitializer {
...
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(Application.class);
}
}
Add tomcat dependency as provided.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifcatId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
For more elaborate information check the reference guide.
Do you mean a tomcat instance on eclipse? What are the logs saying? That there is no application deployed?
Then you need to deploy a war to tomcat -
http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-create-a-deployable-war-file
Change -
<packaging>jar</packaging>
To
<packaging>war</packaging>
And it should work.

Categories