我一直在尝试找出Spring Boot的问题,由于我是Spring的新手,所以我想在这里获得一些帮助。
我有一个基于Spring Boot的Java应用程序,它作为守护程序运行,并向远程服务器发出一些GET请求。(仅充当客户)。
但是我的Spring Boot应用程序在内部启动了嵌入式tomcat容器。我的理解是,如果Java应用程序充当服务器,它将需要tomcat。但是我的应用程序只是远程计算机GET API的使用者,为什么它需要嵌入式tomcat?
在我的pom文件中,我假设甚至进行GET调用都需要使用spring-boot-starter-web。
但是在对禁用嵌入式tomcat进行了一些研究之后,我找到了一个解决方案。
要进行以下更改,
@SpringBootApplication(exclude = {EmbeddedServletContainerAutoConfiguration.class,
WebMvcAutoConfiguration.class})
Run Code Online (Sandbox Code Playgroud)
&in application.yml
spring:
main:
web-environment: false
Run Code Online (Sandbox Code Playgroud)
随着application.yml的更改,我的jar甚至无法启动,直接中止,甚至没有在logback日志中记录任何内容。
现在,如果我删除application.yml更改,则我的jar开始运行(仅在@SpringBootApplication anno中进行第一次更改),但是会出现一些异常。
[main] o.s.boot.SpringApplication : Application startup failed
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
Run Code Online (Sandbox Code Playgroud)
我的疑问是
1)对于只对远程计算机进行GET API调用的应用程序,确实需要tomcat(无论是独立的还是嵌入式的)?
2)我如何克服此异常并安全地删除嵌入式tomcat并仍然执行GET API调用?
我正在使用嵌入式 tomcat,当我尝试启动服务器时,出现以下错误。我正在使用 tomcat 8.0.20 和 jdk8
ERROR {org.apache.catalina.core.ContainerBase} - A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/]]
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:192)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:917)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:871)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1399)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
... 6 more
Caused by: org.apache.catalina.LifecycleException: Failed to initialize component [org.apache.catalina.webresources.StandardRoot@178ad6ef]
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:106)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139)
at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:4840)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4970)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 6 more
Caused by: …Run Code Online (Sandbox Code Playgroud) 我需要在嵌入式 tomcat 中配置 Valve http://tomcat.apache.org/tomcat-8.0-doc/config/valve.html#Remote_IP_Valve 如何做到这一点?
我需要在嵌入式tomcat中配置AJP连接器https://tomcat.apache.org/tomcat-8.0-doc/config/ajp.html 等于如下配置:
<Connector port="8009" protocol="AJP/1.3" redirectPort="8080" />
Run Code Online (Sandbox Code Playgroud)
怎么做?
我新尝试了嵌入式tomcat版本8.0.15。将Maven依赖项下载到我的项目中。
创建必要的上下文和实例。Tomcat服务器正常运行。但是我收到以下警告
Jun 17, 2017 9:50:44 PM org.apache.tomcat.util.scan.StandardJarScanner scan
WARNING: Failed to scan [file:/C:/Users/raghavender.n/.m2/repository/xalan/xalan/2.7.2/xercesImpl.jar] from classloader hierarchy
java.io.FileNotFoundException:C:\Users\raghavender.n\.m2\repository\xalan\xalan\2.7.2\xercesImpl.jar (The system cannot find the file specified)
WARNING: Failed to scan [file:/C:/Users/raghavender.n/.m2/repository/xalan/xalan/2.7.2/xml-apis.jar] from classloader hierarchy
java.io.FileNotFoundException: C:\Users\raghavender.n\.m2\repository\xalan\xalan\2.7.2\xml-apis.jar (The system cannot find the file specified)
<!-- https://mvnrepository.com/artifact/org.apache.tomcat.embed/tomcat-embed-core -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>8.5.15</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
如何禁用/避免来自嵌入式tomcat jar的警告?
Hibernate 正在为 TABLE_PER_CLASS 继承生成临时表,但是 prod。oracle 用户没有那些创建表权限,因此这种方法不是我们项目的选择。
据说 Hibernate Version 5.2.8 解决了这个问题。我们相应地更新了 pom.xml 以覆盖默认的 starter hibernate 版本设置。
仍然我们对以下财产没有任何运气。
<property name="hibernate.hql.bulk_id_strategy"
value="org.hibernate.hql.spi.id.inline.InlineIdsInClauseBulkIdStrategy"
/>
Run Code Online (Sandbox Code Playgroud)
APPLICATION PROPERTIES 也更新如下
**
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@192.168.1. :1521:
spring.datasource.username=
spring.datasource.password=
spring.jpa.hibernate.ddl-auto=none
spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
spring.jpa.show-sql=true
spring.jpa.hibernate.hql.bulk_id_strategy=org.hibernate.hql.spi.id.inline.InlineIdsInClauseBulkIdStrategy
Run Code Online (Sandbox Code Playgroud)
**
此设置在 Spring Boot 应用程序中的正确位置在哪里?
容器仍在测试环境中生成临时表。服务器启动。
亲切的问候
pom.xml 如下
http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0
<groupId>x.xx.ortakonline</groupId>
<artifactId>PolsanOrtakOnlineServer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.0.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<jjwt.version>0.7.0</jjwt.version>
<hibernate.version>5.2.8.Final</hibernate.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-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.4.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId> …Run Code Online (Sandbox Code Playgroud) 我当前正在运行spring-boot version 1.4.0.RELEASE带有嵌入式tomcat的应用程序。包含的Tomcat版本是8.5.4
需要将tomcat版本更新为9.x。当我在这里查看mvnrepository时,我发现tomcat版本有可用的更新9.0.5(如下图所示)
如果无法在我的项目中直接提及此版本,该如何在项目中使用该版本pom.xml?
我不想走传统的部署路线(外部雄猫上的WAR工件)。
当我尝试使用Spring Boot和Spring Data JPA使用嵌入式Tomcat服务器的JNDI数据源时,在使用SpringApplication.run运行应用程序时出现以下错误消息:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Instantiation of bean failed;
nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.entityManagerFactory(org.springframework.boot.autoconfigure.orm.jpa.EntityManagerFactoryBuilder)] threw exception;
nested exception is org.springframework.jndi.JndiLookupFailureException: JndiObjectTargetSource failed to obtain new target object;
nested exception is javax.naming.NameNotFoundException: Name [comp/env/jdbc/myDataSource] is not bound in this Context. Unable to find [comp].
Run Code Online (Sandbox Code Playgroud)
我使用如何在Spring Boot with Embedded Tomcat Container中创建JNDI上下文的解决方案中描述的配置
唯一的区别是对org.springframework.boot的额外Maven依赖:spring-boot-starter-data-jpa
这是一个示例项目:https://github.com/derkoe/spring-boot-sample-tomcat-jndi(这是解决方案中示例的修改版本).只需签出,构建并运行SampleTomcatJndiApplication.
看起来用于查找数据库连接的JNDI上下文不是来自webapp的上下文.这似乎是Spring上下文和Tomcat服务器初始化中的排序问题.
任何想法如何解决?
我正在使用嵌入式 tomcat 开发带有 Spring-boot 的 web 应用程序。此应用程序的要求之一是 2 向 SSL (clientAuth)。
启用 ClientAuth 很容易,但是我们也喜欢使用 spring-boot Actuator 在没有 clientAuth 的情况下管理不同端口上的应用程序。
有没有干净的方法来做到这一点?
(在执行器端点上禁用 SSL 也足够了)
我是 Spring 启动应用程序的新手。我有一个任务来创建应该由休息控制器处理的公共 crud 存储库。我只是从一些例子开始。但是我的应用程序并没有启动嵌入式tomcat。我的休息控制器 URI 也没有映射。这是 maven 模块项目,所有依赖项都在父 maven 中配置。如何解决这个问题。
这是我的代码
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);
}
}
Run Code Online (Sandbox Code Playgroud)
控制器是
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 = …Run Code Online (Sandbox Code Playgroud) 在我的application.yml我设置
server:
tomcat:
basedir: /home/user/TOMCAT
Run Code Online (Sandbox Code Playgroud)
当我运行应用程序时,mvn spring-boot:run我看到该文件夹已创建并且具有此结构
/TOMCAT/work/Tomcat/localhost/ROOT
它是完全空的。
我期待在这里找到一个webapps文件夹等等。这听起来可能很愚蠢,但是,所有与 tomcat 相关的文件在哪里?
Getting this below exception as i am trying to upgrade by Spring Boot parent starter from 1.5 into 2.1.1.Release, but not getting any compilation or any Exception in my Project. Is that i am missing anything here.
Exception in thread "main" java.lang.AbstractMethodError: org.springframework.boot.context.config.ConfigFileApplicationListener.supportsSourceType(Ljava/lang/Class;)Z
at org.springframework.context.event.GenericApplicationListenerAdapter.supportsSourceType(GenericApplicationListenerAdapter.java:79)
at org.springframework.context.event.AbstractApplicationEventMulticaster.supportsEvent(AbstractApplicationEventMulticaster.java:289)
at org.springframework.context.event.AbstractApplicationEventMulticaster.retrieveApplicationListeners(AbstractApplicationEventMulticaster.java:221)
at org.springframework.context.event.AbstractApplicationEventMulticaster.getApplicationListeners(AbstractApplicationEventMulticaster.java:192)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:128)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:75)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:347)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:306)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
at com.nbcuni.compass.schedule.ScheduleServiceApplication.main(ScheduleServiceApplication.java:58)
Run Code Online (Sandbox Code Playgroud)
Same kind of Issue in another service as well.
2018-12-18 12:31:58,999 …Run Code Online (Sandbox Code Playgroud)