我在tomcat上部署应用程序时遇到了一些问题。事情是当我从Child项目部署应用程序然后它工作正常 如果我从父项目运行应用程序,它不会正确加载应用程序。我在tomcat控制台上看到了一些例外 Tomcat是绑定等。
我的问题 - 这可能是应用程序(父级和子级)应用程序都有自己的Application.Java类,因为子项目被添加为父项目中的依赖项?
如果我杀死了java进程,那么它只加载父应用程序但不加载应用程序,当我停止tomcat服务器并再次运行时,同样会再次出现tomcat端口异常。
父项目 的 Example.Java
@RequestMapping("/test/**")
@RestController
public class Example {
@RequestMapping(method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON_VALUE})
public String index() {
return "Hello World";
}
HelloWorldApplication.java
@Configuration
@ComponentScan
@EnableAutoConfiguration
public class HelloWorldApplication {
public static void main(String[] args) {
SpringApplication.run(HelloWorldApplication.class, args);
}
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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>dashboard</groupId>
<artifactId>com.pos.interfaces</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.1.RELEASE</version>
</parent>
<properties>
<!-- The main class to start by executing java -jar -->
<start-class>com.pos.dashboard.backend.HelloWorldApplication</start-class>
</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>jira-widget-app</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>dashboard</groupId>
<artifactId>jira-widget-app</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
儿童项目 的 Example.java
package com.jira.pos.widget;
@RequestMapping("/tester/**")
@RestController
public class Example {
@RequestMapping(method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON_VALUE})
public String index() {
return "Hello World";
}
HelloWorldApplication1 .java
package com.jira.pos.widget;
@Configuration
@ComponentScan
@EnableAutoConfiguration
public class HelloWorldApplication1 {
public static void main(String[] args) {
SpringApplication.run(HelloWorldApplication1.class, args);
}
的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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>dashboard</groupId>
<artifactId>com.pos.interfaces</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<packaging>jar</packaging>
<properties>
<!-- The main class to start by executing java -jar -->
<start-class>com.jira.pos.widget.HelloWorldApplication1</start-class>
</properties>
</project>
此外,两个项目都有自己的服务,jsps和主要方法等。任何想法我怎么能摆脱这个问题?
答案 0 :(得分:0)
从你的问题中完全理解这个问题并不容易,但我认为&#34;两个应用程序都在Tomcat中注册,然后尝试启动它们,因为它们都是以默认端口8080开始的,这可能就是您获取端口绑定异常的原因。
您是否尝试将父级和子级的src / main / resources / application.properties中的属性server.port设置为两个不同的值,例如父母在8282和孩子在8585,看看问题是否仍然存在?