`
wiselyman
  • 浏览: 2093435 次
  • 性别: Icon_minigender_1
  • 来自: 合肥
博客专栏
Group-logo
点睛Spring4.1
浏览量:82287
74ae1471-94c5-3ae2-b227-779326b57435
点睛Spring MVC4...
浏览量:130766
社区版块
存档分类
最新评论

Spring Boot由jar包转成war包

 
阅读更多

spring boot 默认是以jar包形式启动web程序,在新建spring boot项目时候可以选择war包的启动方式。

 

建议在开发的时候建立以jar包启动的web项目,启动效率更快,此时如果想发布成war包形式部署,做如下操作:

1.修改pom.xml

<packaging>jar</packaging>

 

修改成

<packaging>war</packaging>

 

2.新增如下到pom.xml文件中

	<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-tomcat</artifactId>
			<scope>provided</scope>
		</dependency>

 

3.新增ServletInitializer类

import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;

public class ServletInitializer extends SpringBootServletInitializer {

	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
		return application.sources(Application.class);
	}

}

 

新书推荐《JavaEE开发的颠覆者: Spring Boot实战》,涵盖Spring 4.x、Spring MVC 4.x、Spring Boot企业开发实战。

 

京东地址:http://item.jd.com/11894632.html

当当地址:http://product.dangdang.com/23926195.html

亚马逊地址:http://www.amazon.cn/图书/dp/B01D5ZBFUK/ref=zg_bsnr_663834051_6 

淘宝地址:https://item.taobao.com/item.htm?id=528426235744&ns=1&abbucket=8#detail

 

或自己在京东、淘宝、亚马逊、当当、互动出版社搜索自选。

 


6
0
分享到:
评论
17 楼 农村外出务工男JAVA 2017-03-05  
遇到了和大家一样的问,转成war后,,访问404,至今网上没找到解决方案,采用springboot 1.4.3 + jersey 2.x + tomcat 7
16 楼 nnxiaod 2017-03-01  
306274163 写道
  各位问题解决了吗?我也是JAR转成WAR,启动正常该问404



82.2 Create a deployable war file for older servlet containers

Older Servlet containers don’t have support for the ServletContextInitializer bootstrap process used in Servlet 3.0. You can still use Spring and Spring Boot in these containers but you are going to need to add a web.xml to your application and configure it to load an ApplicationContext via a DispatcherServlet.

以上是官方文档,如果你用的是servlet3.0以下的版本(tomcat7以下),是要添加web.xml的,还是升级到tomocat7吧,最简单了。。。
15 楼 306274163 2017-02-08  
  各位问题解决了吗?我也是JAR转成WAR,启动正常该问404
14 楼 fanxl12 2016-12-30  
正确配置如下:
@SpringBootApplication
public class TesttomcatApplication extends SpringBootServletInitializer {

	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
		return application.sources(TesttomcatApplication.class);
	}

//	@Override  复制官方文档上的方法,Application直接导入进去了,实际上应该是TesttomcatApplication
//	protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
//		return application.sources(Application.class);
//	}

	public static void main(String[] args) {
		SpringApplication.run(TesttomcatApplication.class, args);
	}
}
13 楼 fanxl12 2016-12-30  
fanxl12 写道
按照文档,把jar改成war,tomcat启动就报错了,访问404,org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/testtomcat-0.0.1-SNAPSHOT]]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'application': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javafx.application.Application]: Is it an abstract class?; nested exception is java.lang.InstantiationException
不知道哪里出问题了,求解决

解决了自己的问题,看着官方文档配置,自己直接复制过来,没想到官方用的application.sources(Application.class)的Application类直接导入进去了,实际上应该是用自己的类名,望大家不要入坑
12 楼 fanxl12 2016-12-30  
lengyue1127 写道
博主的书我买了也基本看完了,很多测试也做了,基本例子都能调通,但是卡在war包发布这里了,我在网上也查了很多资料,包括官网也看了看。这个问题卡了一周了,不管怎么访问都是404。进不了controller。贴上我代码的信息,博主给的源码也下载和看了,我看很多评论也是卡在这里,博主能看看这个问题吗?

这个是代码入口。
import org.springframework.boot.web.support.SpringBootServletInitializer;

@SpringBootApplication
public class TestWarApplication extends SpringBootServletInitializer{
	
	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
		return application.sources(TestWarApplication.class);
	}

	public static void main(String[] args) {
		SpringApplication.run(TestWarApplication.class, args);
	}
}


这个是controller
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class WarController {
	@RequestMapping("/sayHello")
	public String sayHello() {
		return "sayHello";
	}
}


这个是porm.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.lengyue</groupId>
	<artifactId>com.lengyue</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>war</packaging>

	<name>TestWar</name>
	<description>Demo</description>

	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>1.4.0.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-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>

	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>
</project>


这个是启动日志
  .   ____          _            __ _ _
/\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot ::        (v1.4.0.RELEASE)

2016-09-21 16:22:10.937  INFO 2275 --- [ost-startStop-1] com.lengyue.TestWarApplication           : Starting TestWarApplication v0.0.1-SNAPSHOT on localhost with PID 2275 (/Users/Kandom/Desktop/Spring_Tool_Suite/pivotal-tc-server-developer-3.1.5.RELEASE/base-instance/wtpwebapps/TestWar/WEB-INF/classes started by Kandom in /Users/Kandom/Desktop/Spring_Tool_Suite/STS.app/Contents/MacOS)
2016-09-21 16:22:10.942  INFO 2275 --- [ost-startStop-1] com.lengyue.TestWarApplication           : No active profile set, falling back to default profiles: default
2016-09-21 16:22:10.993  INFO 2275 --- [ost-startStop-1] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@4012eeb: startup date [Wed Sep 21 16:22:10 CST 2016]; root of context hierarchy
2016-09-21 16:22:11.793  INFO 2275 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 801 ms
2016-09-21 16:22:12.285  INFO 2275 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
2016-09-21 16:22:12.286  INFO 2275 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'errorPageFilter' to: [/*]
2016-09-21 16:22:12.286  INFO 2275 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2016-09-21 16:22:12.287  INFO 2275 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2016-09-21 16:22:12.287  INFO 2275 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2016-09-21 16:22:12.287  INFO 2275 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2016-09-21 16:22:12.587  INFO 2275 --- [ost-startStop-1] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@4012eeb: startup date [Wed Sep 21 16:22:10 CST 2016]; root of context hierarchy
2016-09-21 16:22:12.661  INFO 2275 --- [ost-startStop-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/sayHello]}" onto public java.lang.String com.lengyue.controller.WarController.sayHello()
2016-09-21 16:22:12.665  INFO 2275 --- [ost-startStop-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2016-09-21 16:22:12.665  INFO 2275 --- [ost-startStop-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2016-09-21 16:22:12.692  INFO 2275 --- [ost-startStop-1] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-09-21 16:22:12.692  INFO 2275 --- [ost-startStop-1] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-09-21 16:22:12.730  INFO 2275 --- [ost-startStop-1] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-09-21 16:22:12.852  INFO 2275 --- [ost-startStop-1] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2016-09-21 16:22:12.866  INFO 2275 --- [ost-startStop-1] com.lengyue.TestWarApplication           : Started TestWarApplication in 2.539 seconds (JVM running for 4.375)
2016-09-21 16:22:12.940  INFO 2275 --- [ost-startStop-1] org.apache.jasper.servlet.TldScanner     : At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
2016-09-21 16:22:12.982  INFO 2275 --- [ost-startStop-1] org.apache.jasper.servlet.TldScanner     : At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
九月 21, 2016 4:22:12 下午 org.apache.catalina.startup.Catalina start
信息: Server startup in 3601 ms


我在本地是这样访问的
http://localhost:8080/TestWar/sayHello

一直报404的错误。

我这边也是,望解决
11 楼 fanxl12 2016-12-30  
按照文档,把jar改成war,tomcat启动就报错了,访问404,org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/testtomcat-0.0.1-SNAPSHOT]]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'application': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javafx.application.Application]: Is it an abstract class?; nested exception is java.lang.InstantiationException
不知道哪里出问题了,求解决
10 楼 IT小将 2016-12-29  
8楼的问题解决了吗?我也遇到这个问题了
9 楼 zhaoyaoniwo 2016-12-13  
把restcontroller换成controller
8 楼 lengyue1127 2016-09-21  
博主的书我买了也基本看完了,很多测试也做了,基本例子都能调通,但是卡在war包发布这里了,我在网上也查了很多资料,包括官网也看了看。这个问题卡了一周了,不管怎么访问都是404。进不了controller。贴上我代码的信息,博主给的源码也下载和看了,我看很多评论也是卡在这里,博主能看看这个问题吗?

这个是代码入口。
import org.springframework.boot.web.support.SpringBootServletInitializer;

@SpringBootApplication
public class TestWarApplication extends SpringBootServletInitializer{
	
	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
		return application.sources(TestWarApplication.class);
	}

	public static void main(String[] args) {
		SpringApplication.run(TestWarApplication.class, args);
	}
}


这个是controller
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class WarController {
	@RequestMapping("/sayHello")
	public String sayHello() {
		return "sayHello";
	}
}


这个是porm.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.lengyue</groupId>
	<artifactId>com.lengyue</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>war</packaging>

	<name>TestWar</name>
	<description>Demo</description>

	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>1.4.0.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-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>

	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>
</project>


这个是启动日志
  .   ____          _            __ _ _
/\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot ::        (v1.4.0.RELEASE)

2016-09-21 16:22:10.937  INFO 2275 --- [ost-startStop-1] com.lengyue.TestWarApplication           : Starting TestWarApplication v0.0.1-SNAPSHOT on localhost with PID 2275 (/Users/Kandom/Desktop/Spring_Tool_Suite/pivotal-tc-server-developer-3.1.5.RELEASE/base-instance/wtpwebapps/TestWar/WEB-INF/classes started by Kandom in /Users/Kandom/Desktop/Spring_Tool_Suite/STS.app/Contents/MacOS)
2016-09-21 16:22:10.942  INFO 2275 --- [ost-startStop-1] com.lengyue.TestWarApplication           : No active profile set, falling back to default profiles: default
2016-09-21 16:22:10.993  INFO 2275 --- [ost-startStop-1] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@4012eeb: startup date [Wed Sep 21 16:22:10 CST 2016]; root of context hierarchy
2016-09-21 16:22:11.793  INFO 2275 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 801 ms
2016-09-21 16:22:12.285  INFO 2275 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
2016-09-21 16:22:12.286  INFO 2275 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'errorPageFilter' to: [/*]
2016-09-21 16:22:12.286  INFO 2275 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2016-09-21 16:22:12.287  INFO 2275 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2016-09-21 16:22:12.287  INFO 2275 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2016-09-21 16:22:12.287  INFO 2275 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2016-09-21 16:22:12.587  INFO 2275 --- [ost-startStop-1] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@4012eeb: startup date [Wed Sep 21 16:22:10 CST 2016]; root of context hierarchy
2016-09-21 16:22:12.661  INFO 2275 --- [ost-startStop-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/sayHello]}" onto public java.lang.String com.lengyue.controller.WarController.sayHello()
2016-09-21 16:22:12.665  INFO 2275 --- [ost-startStop-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2016-09-21 16:22:12.665  INFO 2275 --- [ost-startStop-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2016-09-21 16:22:12.692  INFO 2275 --- [ost-startStop-1] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-09-21 16:22:12.692  INFO 2275 --- [ost-startStop-1] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-09-21 16:22:12.730  INFO 2275 --- [ost-startStop-1] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-09-21 16:22:12.852  INFO 2275 --- [ost-startStop-1] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2016-09-21 16:22:12.866  INFO 2275 --- [ost-startStop-1] com.lengyue.TestWarApplication           : Started TestWarApplication in 2.539 seconds (JVM running for 4.375)
2016-09-21 16:22:12.940  INFO 2275 --- [ost-startStop-1] org.apache.jasper.servlet.TldScanner     : At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
2016-09-21 16:22:12.982  INFO 2275 --- [ost-startStop-1] org.apache.jasper.servlet.TldScanner     : At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
九月 21, 2016 4:22:12 下午 org.apache.catalina.startup.Catalina start
信息: Server startup in 3601 ms


我在本地是这样访问的
http://localhost:8080/TestWar/sayHello

一直报404的错误。
7 楼 ikinger 2016-09-17  
同样遇到了和一楼同样的问题,访问加上了项目名,index.jsp可以正常访问,就是访问不了controller,不知道为什么,已经困扰很久了。
6 楼 paker1989 2016-08-11  
kucoll 写道
我用spring boot打war包打好了,也部署了,但其中的rest API都是404,是这么回事。
另外你这个类用放在哪里? 随便扔就行了,还是需要在哪里引用这个文件?



请求加上项目名
5 楼 onepieceshin 2015-11-25  
终于找到打包成war部署到tomcat去了,
楼主,我想问为什么要这样才行呢?
4 楼 wiselyman 2015-10-16  
somefuture 写道
这么做的目的是什么?jar和war的优劣势是什么呢


是对目前流行的微服务的响应
3 楼 somefuture 2015-10-07  
这么做的目的是什么?jar和war的优劣势是什么呢
2 楼 wiselyman 2014-11-03  
kucoll 写道
我用spring boot打war包打好了,也部署了,但其中的rest API都是404,是这么回事。
另外你这个类用放在哪里? 随便扔就行了,还是需要在哪里引用这个文件?

放在和Application.java一个目录下
1 楼 kucoll 2014-11-02  
我用spring boot打war包打好了,也部署了,但其中的rest API都是404,是这么回事。
另外你这个类用放在哪里? 随便扔就行了,还是需要在哪里引用这个文件?

相关推荐

    spring boot项目打包成war在tomcat运行的全步骤

    然而,有些场景下可能需要将Spring Boot应用部署到传统的Tomcat服务器上,这时就需要将项目打包成WAR文件。以下是将Spring Boot项目打包成WAR并在Tomcat中运行的详细步骤: 1. **修改打包形式**: 在`pom.xml`文件...

    Springboot 打Jar包,Maven完美解决本地Jar包自动打入Springboot Jar包中

    **Maven 插件** 如`spring-boot-maven-plugin`能够实现将Spring Boot应用打包为可执行的Jar或War文件,并且可以配置不同的参数来控制构建行为。例如,指定主类、排除某些依赖等。 ##### 2. 使用Maven安装本地Jar包 ...

    实现spring boot与普通jar加密

    Spring Boot简化了Java应用的创建和部署,通过内嵌的Servlet容器(如Tomcat或Jetty)可以直接运行为可执行的JAR或WAR文件。为了加密这样的JAR文件,我们需要采取以下步骤: 1. **选择加密算法**:选择合适的加密...

    SpringBoot项目如何将jar包打包成war包.pdf

    这样Maven会知道你需要生成war包而不是jar包。 ```xml &lt;packaging&gt;war ``` 2. **排除SpringBoot内置的Tomcat容器**: SpringBoot默认包含了一个嵌入式的Tomcat服务器,但在打包war时,我们需要排除这个内置的...

    spring boot 所有‘demo,打包下载’

    Spring Boot 是一个由 Pivotal 团队开发的框架,旨在简化 Spring 应用程序的初始搭建以及开发过程。它提供了预配置的依赖项和自动配置功能,使得开发者可以快速地创建生产级别的 Java 应用。这个“spring boot 所有...

    Spring Boot讲义.pdf

    - **独立运行的Spring应用**:Spring Boot可以创建独立的Spring应用程序,开发者无需部署WAR包到外部的Servlet容器中。 - **内嵌的服务器**:如Tomcat、Jetty或Undertow等,使得项目可以打包成一个JAR文件直接运行...

    十分钟上手spring boot

    - 将Spring Boot应用打包成一个可执行的jar文件。 **12. 接下来阅读什么** - 继续深入学习Spring Boot的更多特性和高级主题。 - 探索如何使用Spring Boot构建微服务架构。 - 学习如何对Spring Boot应用进行单元...

    项目打包成War(Spring Boot).pdf

    ### Spring Boot 项目打包成WAR 文件详解 #### 一、背景介绍 在传统的Java Web开发中,项目通常被打包成WAR文件(Web Application Archive),这种格式的文件包含了Web应用程序的所有资源,包括HTML、CSS、...

    springboot 打包war包

    Spring Boot默认生成的是可执行的JAR包,但有时我们需要将其部署到传统的Web服务器如Tomcat上,这时就需要将Spring Boot项目打包为WAR包。Spring Boot支持通过修改`pom.xml`文件的打包类型(packaging)为`war`来...

    Spring Boot面试题(92题)

    首先,它可以独立运行,无需打成war包部署到服务器,只需要生成一个可执行的jar包即可运行。其次,它通过`spring-boot-starter`模块减少了Maven配置,比如`spring-boot-starter-web`自动引入了Web开发所需的依赖。...

    解决spring boot + jar打包部署tomcat 404错误问题

    1.spring boot 不支持jsp打jar包,jsp只能打war包. 方法: &lt;packaging&gt;war &lt;groupId&gt;org.springframework.boot &lt;artifactId&gt;spring-boot-maven-plugin 2.tomcat版本不能太新,太新容易不...

    spring boot 小例子

    描述中提到"直接打包成war包,部署到tomcat下",这是标准的 Java Web 应用部署流程。Spring Boot 项目通过 Maven 或 Gradle 构建系统打包成 WAR 文件后,可以将该文件复制到 Tomcat 的 webapps 目录下。当 Tomcat ...

    Spring Boot-实战

    8. **部署与运行**:讨论如何打包Spring Boot应用为可执行JAR或WAR文件,以及如何在Docker容器、云平台(如Heroku)上部署应用。 9. **微服务架构**:可能涉及如何使用Spring Cloud构建微服务,包括服务发现、配置...

    mybatis-spring-boot-starter-2.1.4.jar

    mybatis-spring-boot-starter-2.1.4.jarmybatis-spring-boot-starter-2.1.4.jar

    spring boot 相关技术

    Spring Boot 是一个由 Pivotal 团队开发的框架,旨在简化 Spring 应用程序的初始搭建以及开发过程。它提供了预配置的依赖项和自动配置功能,使得开发者可以快速地创建生产级别的基于 Spring 的应用程序。 《Spring ...

    Spring Boot+maven打war包的方法

    Spring Boot+maven打war包的方法 Spring Boot框架是一个基于Java的开源框架,旨在简化基于Java的Web应用程序的开发。maven是一个项目管理和构建工具,通过pom.xml文件管理项目的依赖关系和编译过程。今天,我们将...

    Spring Boot打包war jar 部署tomcat

    Spring Boot 打包 war jar 部署 tomcat Spring Boot 是一个基于 Java 的框架,用于快速构建独立的生产级别的基于 Spring 框架的应用程序。在实际开发中,我们经常需要将 Spring Boot 应用程序部署到 tomcat 服务器...

    Spring Boot in Action 英文版

    Spring Boot还支持内嵌的Servlet容器,比如Tomcat、Jetty或Undertow,这意味着开发者可以不用部署到传统的WAR文件中,而是直接运行一个JAR文件,并且应用程序会启动内嵌的Servlet容器。这简化了部署过程,使得开发...

    springboot_jsp_maven(war+jar).rar

    而"亮点是不仅可以war包方式运行,还可以可执行jar包方式运行",这一点揭示了Spring Boot的一个核心特性——内嵌式Servlet容器,如Tomcat。通常,Spring Boot应用可以被打包为可执行的jar,其中包含了运行应用所需的...

Global site tag (gtag.js) - Google Analytics