如何将子域重写为路径?
例:
或者更好的是(反向文件夹):
请求foo.bar .example.com应该在/ src/main/resources/static/bar/foo /index.html中发送文件.
使用Apache2,它由mod_rewrite完成.我找到了有关使用Tomcat 8重写的文档,但问题是在哪里使用spring boot放置这些文件?
更新
我尝试使用UrlRewriteFilter,但似乎无法使用正则表达式替换在域路径中定义规则.
这是我的配置:
Maven依赖:
<dependency>
<groupId>org.tuckey</groupId>
<artifactId>urlrewritefilter</artifactId>
<version>4.0.3</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
Spring Java Config注册Servlet过滤器:
@Configuration
@ComponentScan
@EnableAutoConfiguration
public class Application
{
public static void main(String[] args)
{
SpringApplication.run(Application.class, args);
}
@Bean
public FilterRegistrationBean filterRegistrationBean()
{
FilterRegistrationBean registrationBean = new FilterRegistrationBean();
registrationBean.setFilter(new UrlRewriteFilter());
registrationBean.addUrlPatterns("*");
registrationBean.addInitParameter("confReloadCheckInterval", "5");
registrationBean.addInitParameter("logLevel", "DEBUG");
return registrationBean;
} …Run Code Online (Sandbox Code Playgroud) 我正在编写一个基于spring boot的应用程序,并注意到chrome中的一些警告.它抱怨说例如web字体(扩展名woff)是以普通/文本而不是正确的mime类型发送的.
我正在使用静态文件的常规机制,无需特殊配置.我找到的源代码看起来不可能为"stock"ResourceHandler添加更多的mimetypes.Resourcehandler将mime类型识别调度到servlet容器,这是spring-boot 1.2的默认tomcat.
我错过了什么吗?有人知道一种简单的方法来增强资源映射以使用正确的mime类型提供更多文件类型吗?
现在,我正在考虑编写一个针对静态内容触发的过滤器,并在事后删除mimetypes.也许我应该在springsource创建一个功能请求...... ;-)
我已将最大文件大小设置为
multipart.maxFileSize: 1mb
multipart.maxRequestSize: 1mb
Run Code Online (Sandbox Code Playgroud)
这是我的控制器:
@RequestMapping(method=RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@ResponseStatus(HttpStatus.CREATED)
@Secured(Privileges.CAN_USER_READ)
public void create(@RequestParam("file")final MultipartFile file,Principal principal) throws IllegalStateException, IOException,MultipartException{
medicalHistoryService.create(new MedicalHistory(file));
}
Run Code Online (Sandbox Code Playgroud)
这是错误消息
2016-03-03 13:48:24.560 WARN 4992 --- [nio-8080-exec-1] h.c.w.RestResponseEntityExceptionHandler : Could not parse multipart servlet request; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (9288401) exceeds the configured maximum (1048576)
2016-03-03 13:48:25.545 WARN 4992 --- [nio-8080-exec-2] h.c.w.RestResponseEntityExceptionHandler : Could not parse multipart servlet request; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException: the …Run Code Online (Sandbox Code Playgroud) spring multipartform-data multipart spring-boot embedded-tomcat-8
传统上,通过将生成的war部署到Tomcat的-webapps-目录,将Servlet Maven项目部署到Tomcat生产服务器。但是,Spring-Boot 作为一种实用的趋势,推荐jar超过war. 这种偏好对测试没有问题,但如果部署到生产中现有的 Tomcat 服务器,AFAIK,只接受战争。所以我的解决方案是:
packaging元素作为war这样:<packaging>war</packaging>。但这显然是一个额外的步骤问题:以上的解决方案好吗?或者还有其他更好的部署到生产的解决方案吗?如果是第三种方案,据我所知只有Tomcat7 Maven插件,如果我只想用Tomcat 8或Tomcat 9测试怎么办?我尝试使用主类来启动嵌入式Tomcat,但是处理依赖项非常困难
我正在从 JBoss/Wildfly 移植一个旧应用程序以在 tomcat 上运行。我能够使用网络上的资源完成的大多数事情。但是,我对最新一期的运气不太好。我很早就知道我必须添加
providedRuntime('org.apache.tomcat.embed:tomcat-embed-jasper')
Run Code Online (Sandbox Code Playgroud)
作为请求路由的依赖项。如果我不包含此依赖项,则在发出请求时会出现 404 错误。现在,这似乎对我的应用程序没有任何不利影响,但如果没有任何问题,我不喜欢启动错误。
其目标环境是运行 Tomcat 8 的 AWS,并且在部署时运行良好。我只看到在本地运行的这个错误(启用调试):
2017-04-10 09:40:26.957 DEBUG 45630 --- [ost-startStop-1] o.a.tomcat.util.scan.StandardJarScanner : Scanning JAR [file:/Users/bhodgson/.gradle/caches/modules-2/files-2.1/org.apache.velocity/velocity/1.6.2/1b470ec12a9b8aa69b0458a7e477dacb2cbdd6a0/velocity-1.6.2.jar] from classpath
2017-04-10 09:40:26.958 DEBUG 45630 --- [ost-startStop-1] o.a.tomcat.util.scan.StandardJarScanner : Scanning JAR [file:/Users/bhodgson/.gradle/caches/modules-2/files-2.1/net.minidev/accessors-smart/1.1/a527213f2fea112a04c9bdf0ec0264e34104cd08/accessors-smart-1.1.jar] from classpath
2017-04-10 09:40:26.958 DEBUG 45630 --- [ost-startStop-1] o.a.tomcat.util.scan.StandardJarScanner : Scanning JAR [file:/Users/bhodgson/.gradle/caches/modules-2/files-2.1/com.googlecode.json-simple/json-simple/1.1.1/c9ad4a0850ab676c5c64461a05ca524cdfff59f1/json-simple-1.1.1.jar] from classpath
2017-04-10 09:40:26.958 DEBUG 45630 --- [ost-startStop-1] o.a.tomcat.util.scan.StandardJarScanner : Scanning JAR [file:/Users/bhodgson/.gradle/caches/modules-2/files-2.1/org.objenesis/objenesis/2.1/87c0ea803b69252868d09308b4618f766f135a96/objenesis-2.1.jar] from classpath
2017-04-10 09:40:26.959 DEBUG 45630 --- [ost-startStop-1] o.a.tomcat.util.scan.StandardJarScanner : Scanning JAR [file:/Users/bhodgson/.gradle/caches/modules-2/files-2.1/com.sun.xml.bind/jaxb-core/2.2.11/c3f87d654f8d5943cd08592f3f758856544d279a/jaxb-api.jar] from classpath
2017-04-10 …Run Code Online (Sandbox Code Playgroud) 使用vaadin push的Spring-Boot,Vaadin 8应用程序
@Push(transport = Transport.WEBSOCKET_XHR)
Run Code Online (Sandbox Code Playgroud)
如果应用程序在没有任何暂停的情况下获得用户操 没有任何用户请求/操作的几秒钟在控制台上出现以下错误.这使我们的错误日志文件涂鸦.先感谢您.
Spring-boot,vaadin 8,Nginx,Plesk onyx,ubuntu 16,let-encrypt
java.io.IOException: Unable to unwrap data, invalid status [CLOSED]
at org.apache.tomcat.util.net.SecureNioChannel.read(SecureNioChannel.java:604)
at org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.fillReadBuffer(NioEndpoint.java:1240)
at org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.fillReadBuffer(NioEndpoint.java:1213)
at org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.read(NioEndpoint.java:1186)
at org.apache.tomcat.websocket.server.WsFrameServer.onDataAvailable(WsFrameServer.java:72)
at org.apache.tomcat.websocket.server.WsFrameServer.doOnDataAvailable(WsFrameServer.java:171)
at org.apache.tomcat.websocket.server.WsFrameServer.notifyDataAvailable(WsFrameServer.java:151)
at org.apache.tomcat.websocket.server.WsHttpUpgradeHandler.upgradeDispatch(WsHttpUpgradeHandler.java:148)
at org.apache.coyote.http11.upgrade.UpgradeProcessorInternal.dispatch(UpgradeProcessorInternal.java:54)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:53)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
Run Code Online (Sandbox Code Playgroud)
nginx配置:
location / {
proxy_pass https://ip:port;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Accel-Internal /internal-nginx-static-location;
access_log off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade"; …Run Code Online (Sandbox Code Playgroud) 我创建了一个简单的测试应用程
import java.util.logging.Logger;
import org.apache.catalina.Context;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.startup.Tomcat;
public class Main {
private final static Logger LOGGER = Logger.getLogger(Main.class.getName());
private final static String mWorkingDir = System.getProperty("java.io.tmpdir");
private static Tomcat tomcat = null;
public static void main(String[] args) {
tomcat = new Tomcat();
tomcat.setPort(8080);
tomcat.setBaseDir(mWorkingDir);
tomcat.getHost().setAppBase(mWorkingDir);
tomcat.getHost().setAutoDeploy(true);
tomcat.getHost().setDeployOnStartup(true);
try {
tomcat.start();
} catch (LifecycleException e) {
LOGGER.severe("Tomcat could not be started.");
e.printStackTrace();
}
LOGGER.info("Tomcat started on " + tomcat.getHost());
// Alternatively, you can specify a WAR file as last parameter …Run Code Online (Sandbox Code Playgroud) 我正在使用嵌入式Tomcat 8.5.4,即
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>8.5.4</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
实现工作完美(Tomcat就像魅力一样),唯一困扰我的是嵌入式Tomcat登录System.out.在我的应用程序内部,我正在使用log4j日志记录,因此这会导致以下日志记录混合(而不是将Tomcat记录到任何文件):
...
2017-07-30 17:57:54 DEBUG EmbeddedTomcat:136 - Binding servlet 'sample' to path '/sample/*'.
Jul 30, 2017 5:57:54 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-15000"]
Jul 30, 2017 5:57:54 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Jul 30, 2017 5:57:54 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Tomcat
Jul 30, 2017 5:57:54 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/8.5.4
Jul 30, 2017 5:57:54 PM org.apache.coyote.AbstractProtocol …Run Code Online (Sandbox Code Playgroud) 我正在尝试设置一个基本的嵌入式 Tomcat 服务器,但无法运行 Tomcat 服务器。
public class Main {
public static void main(String[] args) throws LifecycleException {
Tomcat tomcat = new Tomcat();
tomcat.setPort(8888);
tomcat.start();
tomcat.getServer().await();
}
}
Run Code Online (Sandbox Code Playgroud)
在 Eclipse 中运行这个 java 应用程序提供输出:
2019 年 6 月 19 日下午 12:00:00 org.apache.catalina.core.StandardService startInternal
信息:启动服务 [Tomcat]
然后等到我按预期停止,但是当我curl localhost:8888在终端中运行时,我得到curl: (7) Failed connect to localhost:8888; 连接被拒绝。
我完全按照本教程进行操作,但似乎无法让服务器实际运行。此外,netstat -nlt不显示端口8888正在打开。
我build.gradle有一个依赖:
implementation 'org.apache.tomcat.embed:tomcat-embed-core:9.0.21'
Run Code Online (Sandbox Code Playgroud)
有什么我在这里想念的吗?
嵌入式tomcat或任何此类嵌入式服务器可以用于生产环境中的微服务吗?嵌入式服务器如何与普通的独立完整服务器不同(性能.可靠性明智)?嵌入式服务器与独立服务器相比重量轻吗?嵌入式服务器与其独立服务器相比没有什么功能?我们可以更改嵌入式tomcat中的默认安全设置,密码等高级内容吗?
java ×6
spring-boot ×6
tomcat ×4
spring-mvc ×2
gradle ×1
kubernetes ×1
lets-encrypt ×1
log4j ×1
logging ×1
maven ×1
mime-types ×1
multipart ×1
nginx ×1
spring ×1
tomcat8 ×1
vaadin ×1
vaadin-push ×1
vaadin7 ×1
vaadin8 ×1