mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-07-15 01:07:30 +08:00
Merge branch '2.5.x'
Closes gh-28166
This commit is contained in:
commit
29637706a9
@ -13,7 +13,6 @@ configurations {
|
||||
dependencies {
|
||||
app project(path: ":spring-boot-project:spring-boot-dependencies", configuration: "mavenRepository")
|
||||
app project(path: ":spring-boot-project:spring-boot-parent", configuration: "mavenRepository")
|
||||
app project(path: ":spring-boot-project:spring-boot-starters:spring-boot-starter-web", configuration: "mavenRepository")
|
||||
app project(path: ":spring-boot-project:spring-boot-tools:spring-boot-gradle-plugin", configuration: "mavenRepository")
|
||||
|
||||
intTestImplementation(enforcedPlatform(project(":spring-boot-project:spring-boot-parent")))
|
||||
|
@ -13,7 +13,7 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("org.springframework.boot:spring-boot-starter-web")
|
||||
implementation("org.apache.tomcat.embed:tomcat-embed-core")
|
||||
}
|
||||
|
||||
bootJar {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
* Copyright 2012-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -16,14 +16,73 @@
|
||||
|
||||
package org.springframework.boot.launchscript;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.security.CodeSource;
|
||||
import java.security.ProtectionDomain;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.catalina.Context;
|
||||
import org.apache.catalina.LifecycleException;
|
||||
import org.apache.catalina.startup.Tomcat;
|
||||
|
||||
@SpringBootApplication
|
||||
public class LaunchScriptTestApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(LaunchScriptTestApplication.class, args);
|
||||
public static void main(String[] args) throws LifecycleException {
|
||||
System.out.println("Starting " + LaunchScriptTestApplication.class.getSimpleName() + " (" + findSource() + ")");
|
||||
Tomcat tomcat = new Tomcat();
|
||||
tomcat.getConnector().setPort(getPort(args));
|
||||
Context context = tomcat.addContext(getContextPath(args), null);
|
||||
tomcat.addServlet(context.getPath(), "test", new HttpServlet() {
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
|
||||
throws ServletException, IOException {
|
||||
resp.getWriter().println("Launched");
|
||||
}
|
||||
|
||||
});
|
||||
context.addServletMappingDecoded("/", "test");
|
||||
tomcat.start();
|
||||
}
|
||||
|
||||
private static URL findSource() {
|
||||
try {
|
||||
ProtectionDomain domain = LaunchScriptTestApplication.class.getProtectionDomain();
|
||||
CodeSource codeSource = (domain != null) ? domain.getCodeSource() : null;
|
||||
return (codeSource != null) ? codeSource.getLocation() : null;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static int getPort(String[] args) {
|
||||
String port = getProperty(args, "server.port");
|
||||
return (port != null) ? Integer.parseInt(port) : 8080;
|
||||
}
|
||||
|
||||
private static String getContextPath(String[] args) {
|
||||
String contextPath = getProperty(args, "server.servlet.context-path");
|
||||
return (contextPath != null) ? contextPath : "";
|
||||
}
|
||||
|
||||
private static String getProperty(String[] args, String property) {
|
||||
String value = System.getProperty(property);
|
||||
if (value != null) {
|
||||
return value;
|
||||
}
|
||||
String prefix = "--" + property + "=";
|
||||
for (String arg : args) {
|
||||
if (arg.startsWith(prefix)) {
|
||||
return arg.substring(prefix.length());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,30 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.launchscript;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class LaunchVerificationController {
|
||||
|
||||
@RequestMapping("/")
|
||||
public String verifyLaunch() {
|
||||
return "Launched\n";
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user