[SPRING] Tomcat에 Spring 부트 배치
SPRINGTomcat에 Spring 부트 배치
그래서 나는 봄을 처음 사용하기 때문에 봄 부팅을 시도 할 것이라고 생각했다.
나는 빌드하기 위해 Maven을 사용하고있다. - 뷰 요청을 설정한다. "App"으로 실행하면 자체가 바람둥이를 시작하고 디폴트 8080 포트에서 서비스를 얻는다. 그래서 localhost : 8080 / service를 호출하면된다. 문제 없다.
그러나 내가 서버로 배포 할 WAR로 패키지하려고하면 작동하지 않습니다.
그래서 나는 기본으로 돌아가서 그것을 내 tomcat 서버에 로컬로 배포하고 어떤 일이 일어날지를 생각했다.
그래서 처음에는 아무 일도 없었습니다. - 404 - 인터넷 검색을 약간 해보았습니다. 이처럼 웹 엔트리 포인트를 포함해야합니다. 여기에 내 메인 클래스가 있습니다.
@ComponentScan
@EnableAutoConfiguration
public class App extends SpringBootServletInitializer
{
public static void main( String[] args ) {
SpringApplication.run(App.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(appClass);
}
private static Class<App> appClass = App.class;
}
그래서 그것이 작동하는 것처럼 보였습니다, 콘솔에서 나는 빨간 카탈로니아 스타트 업 텍스트를 볼 수있었습니다, 그리고 나서 나는 봄 부팅을 보았습니다 (나는 전에는 보지 못했습니다)
그러나 내가 localhost : 8080 / service라는 서비스를 시도 할 때 나는 여전히 404를 얻는다.
내가 그것을 "App"으로 돌릴 때 그것은 치료를한다.
내가해야 할 일이 분명해? 전쟁을 만들뿐입니다.
WAR 파일의 압축을 풀었습니다. WEB-INF와 종속 관계가 있습니다.
어떤 도움도 좋을 것입니다 - 스프링 부트 응용 프로그램을 WAR로 배포 할 때 비슷한 문제가있는 사람이 있습니까?
***최신 정보****
이제 내 로컬 Tomcat 7 서버에 올바르게 배포 할 전쟁을 얻을 수 있습니다.하지만 외부에서 호스팅되는 Tomcat 컨테이너에 배포하려고하면
at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:175)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5262)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 15 more
Jul 14, 2014 1:49:01 PM org.apache.catalina.startup.HostConfig deployDirectory
SEVERE: Error deploying web application directory /usr/local/shared/tomcat/thecookpot/webapps/cookpot
java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/cookpot]]
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:898)
at org.apache.catalina.core.ContainerBase.access$000(ContainerBase.java:130)
at org.apache.catalina.core.ContainerBase$PrivilegedAddChild.run(ContainerBase.java:153)
at org.apache.catalina.core.ContainerBase$PrivilegedAddChild.run(ContainerBase.java:142)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:869)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1095)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1617)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Jul 14, 2014 1:49:01 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /usr/local/shared/tomcat/thecookpot/webapps/examples
Jul 14, 2014 1:49:01 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /usr/local/shared/tomcat/thecookpot/webapps/host-manager
Jul 14, 2014 1:49:01 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /usr/local/shared/tomcat/thecookpot/webapps/CookPot
Jul 14, 2014 1:49:02 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(/usr/local/shared/tomcat/thecookpot/webapps/CookPot/WEB-INF/lib/tomcat-embed-core-7.0.52.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
Jul 14, 2014 1:49:02 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(/usr/local/shared/tomcat/thecookpot/webapps/CookPot/WEB-INF/lib/tomcat-embed-el-7.0.52.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/el/Expression.class
Jul 14, 2014 1:49:06 PM org.apache.catalina.core.ContainerBase addChildInternal
SEVERE: ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/CookPot]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:895)
at org.apache.catalina.core.ContainerBase.access$000(ContainerBase.java:130)
at org.apache.catalina.core.ContainerBase$PrivilegedAddChild.run(ContainerBase.java:153)
at org.apache.catalina.core.ContainerBase$PrivilegedAddChild.run(ContainerBase.java:142)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:869)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1095)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1617)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.security.AccessControlException: access denied (java.util.PropertyPermission java.awt.headless write)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)
at java.security.AccessController.checkPermission(AccessController.java:546)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at java.lang.System.setProperty(System.java:727)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:263)
at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:130)
at org.springframework.boot.context.web.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:89)
at org.springframework.boot.context.web.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:51)
at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:175)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5262)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 15 more
Jul 14, 2014 1:49:06 PM org.apache.catalina.startup.HostConfig deployDirectory
SEVERE: Error deploying web application directory /usr/local/shared/tomcat/thecookpot/webapps/CookPot
java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/CookPot]]
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:898)
at org.apache.catalina.core.ContainerBase.access$000(ContainerBase.java:130)
at org.apache.catalina.core.ContainerBase$PrivilegedAddChild.run(ContainerBase.java:153)
at org.apache.catalina.core.ContainerBase$PrivilegedAddChild.run(ContainerBase.java:142)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:869)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1095)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1617)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Jul 14, 2014 1:49:06 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /usr/local/shared/tomcat/thecookpot/webapps/ROOT
Jul 14, 2014 1:49:06 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /usr/local/shared/tomcat/thecookpot/webapps/manager
Jul 14, 2014 1:49:06 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /usr/local/shared/tomcat/thecookpot/webapps/docs
Jul 14, 2014 1:49:06 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /usr/local/shared/tomcat/thecookpot/webapps/Cookpot
Jul 14, 2014 1:49:06 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(/usr/local/shared/tomcat/thecookpot/webapps/Cookpot/WEB-INF/lib/tomcat-embed-core-7.0.52.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
Jul 14, 2014 1:49:06 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(/usr/local/shared/tomcat/thecookpot/webapps/Cookpot/WEB-INF/lib/tomcat-embed-el-7.0.52.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/el/Expression.class
Jul 14, 2014 1:49:09 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-6350"]
Jul 14, 2014 1:49:09 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-4350"]
Jul 14, 2014 1:49:09 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 17529 ms
해결법
-
==============================
1.스프링 부트 참조 문서의 실행 파일 jar 및 war 파일 패키징의 내용은 다음과 같이 설명합니다.
스프링 부트 참조 문서의 실행 파일 jar 및 war 파일 패키징의 내용은 다음과 같이 설명합니다.
<?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>
-
==============================
2.아래 코드는 바람둥이 의존성이없는 tomcat8 배포에서 잘 작동했습니다.
아래 코드는 바람둥이 의존성이없는 tomcat8 배포에서 잘 작동했습니다.
@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;
}
종속성 이하는 필요하지 않습니다.
<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")
-
==============================
3.Spring Boot를 선택할 때 WAR을 생성하고 싶지 않습니다. 루트 페이지에서 :
Spring Boot를 선택할 때 WAR을 생성하고 싶지 않습니다. 루트 페이지에서 :
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)
편집 : 그래서, 목적이 "Spring Boot 시도"라면, WAR 파일을 생성하지 말 것을 제안합니다.
WAR 파일을 생성해야한다면 (SpringBoot에 대한 코드를 유지하고 표준 서블릿 컨테이너에서 실행할 수있는 파일을 생성해야한다.) Spring 부트 JAR 애플리케이션을 WAR로 변환하는 문서를 읽어야한다.
빌드 프로세스에 spring-boot-maven-plugin을 포함 시켰습니까? 이 단계를 설명하지 않았습니다 ...
from https://stackoverflow.com/questions/24741816/deploy-spring-boot-to-tomcat by cc-by-sa and MIT license