java Spring 启动应用程序未启动嵌入式 tomcat
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46617885/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Spring boot application not starting embedded tomcat
提问by Muthu vignesh k
Am newbie to Spring boot application. I have a task to create common crud repository which should be processed by rest controller. I just started with some example. But my application is not started the embedded tomcat. Also my rest controller URI are not mapping. This is maven module project and all the dependency are configured in parent maven. How to resolve this.
我是 Spring 启动应用程序的新手。我有一个任务来创建公共 crud 存储库,该存储库应由其余控制器处理。我只是从一些例子开始。但是我的应用程序并没有启动嵌入式tomcat。我的休息控制器 URI 也没有映射。这是 maven 模块项目,所有依赖项都在父 maven 中配置。如何解决这个问题。
Here is my code
这是我的代码
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class CRUDEngineApplication {
public static void main(String[] args) {
SpringApplication.run(CRUDEngineApplication.class, args);
}
}
Controller is
控制器是
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import com.scm.services.CRUDEngineService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@RestController("/api")
public class CRUDEngineController {
@Autowired
private CRUDEngineService crudEngineService;
public static final Logger logger =
LoggerFactory.getLogger(CRUDEngineController.class);
/* public void setProductService(CRUDEngineService crudEngineService) {
this.crudEngineService = crudEngineService;
}*/
@RequestMapping(value = "/user", method = RequestMethod.POST)
public ResponseEntity<?> createUser(@RequestBody Object entity) {
System.out.println("Check point entered.");
crudEngineService.save(entity);
return new ResponseEntity<String>( HttpStatus.CREATED);
}
}
Service interface is
服务接口是
import java.util.UUID;
public interface CRUDEngineService {
void save(Object entity);
void delete(UUID id);
}
Service implementation class is
服务实现类是
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.scm.repositories.CRUDEngineRespository;
import java.util.UUID;
@Service
public class CRUDEngineServiceImpl implements CRUDEngineService {
@Autowired
private CRUDEngineRespository productRepository;
@Override
public void save(Object entity) {
productRepository.save(entity);
}
@Override
public void delete(UUID id) {
productRepository.delete(id);
}
}
And the crud repository implementation is
并且 crud 存储库实现是
import java.util.UUID;
import org.springframework.data.repository.CrudRepository;
public interface CRUDEngineRespository extends CrudRepository<Object, UUID>
{
}
Child pom.xml is
子 pom.xml 是
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.scm</groupId>
<artifactId>scm-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>crudEngineService</artifactId>
<packaging>war</packaging>
<name>crudEngineService</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Parent pom is
父 pom 是
<?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.scm</groupId>
<artifactId>scm-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>scm-parent</name>
<description>scm project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.7.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-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-cassandra</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-validator -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.4.1.Final</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<modules>
<module>userService</module>
<module>authenticationService</module>
<module>dataLayerService</module>
<module>uiService</module>
<module>crudEngineService</module>
</modules>
And the console result is
控制台结果是
2017-10-07 13:03:32.348 INFO 6508 --- [ main]
c.s.configuration.CRUDEngineApplication : Starting CRUDEngineApplication on
STS-STP-A808 with PID 6508 (started by muthuvignesh.k in E:\Septa_Bench\STS
Septa Repo\ppts_scm\scm-parent\crudEngineService)
2017-10-07 13:03:32.350 INFO 6508 --- [ main]
c.s.configuration.CRUDEngineApplication : No active profile set, falling
back to default profiles: default
2017-10-07 13:03:32.378 INFO 6508 --- [ main]
s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@4df828
d7: startup date [Sat Oct 07 13:03:32 IST 2017]; root of context hierarchy
2017-10-07 13:03:32.766 WARN 6508 --- [ main]
o.h.v.m.ParameterMessageInterpolator : HV000184:
ParameterMessageInterpolator has been chosen, EL interpolation will not be supported
2017-10-07 13:03:32.872 WARN 6508 --- [ main] o.h.v.m.ParameterMessageInterpolator : HV000184: ParameterMessageInterpolator has been chosen, EL interpolation will not be supported
2017-10-07 13:03:33.052 INFO 6508 --- [ main] com.datastax.driver.core.Native : Could not load JNR C Library, native system calls through this library will not be available (set this logger level to DEBUG to see the full stack trace).
2017-10-07 13:03:33.052 INFO 6508 --- [ main] com.datastax.driver.core.ClockFactory : Using java.lang.System clock to generate timestamps.
2017-10-07 13:03:33.197 INFO 6508 --- [ main] com.datastax.driver.core.NettyUtil : Did not find Netty's native epoll transport in the classpath, defaulting to NIO.
2017-10-07 13:03:33.541 INFO 6508 --- [ main] c.d.d.c.p.DCAwareRoundRobinPolicy : Using data-center name 'datacenter1' for DCAwareRoundRobinPolicy (if this is incorrect, please provide the correct datacenter name with DCAwareRoundRobinPolicy constructor)
2017-10-07 13:03:33.543 INFO 6508 --- [ main] com.datastax.driver.core.Cluster : New Cassandra host /10.10.30.125:9042 added
2017-10-07 13:03:33.795 INFO 6508 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2017-10-07 13:03:33.804 INFO 6508 --- [ main] c.s.configuration.CRUDEngineApplication : Started CRUDEngineApplication in 1.619 seconds (JVM running for 2.002)
回答by Dhiraj Ray
Remove <scope>provided</scope>
from pom.xml and try re-running. Use providedif you wish to deploy the war to any other standalone tomcat.
<scope>provided</scope>
从 pom.xml 中删除并尝试重新运行。如果您希望将War部署到任何其他独立的 tomcat,请使用提供的。
Reference: Spring Boot Embedded Tomcat
回答by Amit Datta
Try dependency management:
尝试依赖管理:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>