Use case: We are trying to host dev and test environment of our spring boot application on an aws instance. Config used is Ubuntu 20.04, tomcat 9.0.7 and open jdk 11.
We have configured profiles for specific environments and properties files for each profile (viz. Dev, Test, Prod).
Virtual hosts have been added to tomcats server.xml file as below.
<Host name="devbty.transp.in" appBase="webappbackend" unpackWARs="true" autoDeploy="true">
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="dev_bty_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
<Host name="testbty.transp.in" appBase="webappbackendtest" unpackWARs="true" autoDeploy="true">
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="test_bty_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
Appbase directories are created in /opt/tomcat/ directory. After deployment tomcat initializes only one(dev) app and the second one(test) is extracted from the WAR and present inside the appbase directory but not initialized. After hitting the respective URL's the output is as below.
Dev
Test
Dev is accessible whereas test is not.
The logs too show similar story. Here's a snippet from the catalina.out.
:: Spring Boot :: (v2.7.6)
2023-02-17 07:39:59.644 INFO 19257 --- [ main] in.bilty.Application : Starting Application using Java 11.0.17 on ip-20-0-2-81 with PID 19257 (/opt/tomcat/webappbackend/ROOT/WEB-INF/classes started by root in /)
2023-02-17 07:39:59.656 INFO 19257 --- [ main] in.bilty.Application : The following 1 profile is active: "Dev"
2023-02-17 07:40:01.860 INFO 19257 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2023-02-17 07:40:02.065 INFO 19257 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 188 ms. Found 14 JPA repository interfaces.
17-Feb-2023 07:40:02.929 INFO [main] org.apache.catalina.core.ApplicationContext.log Initializing Spring embedded WebApplicationContext
2023-02-17 07:40:02.929 INFO 19257 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initi
It however finds 2 applications on the classpath
17-Feb-2023 07:39:58.354 INFO [main] org.apache.catalina.core.ApplicationContext.log 2 Spring WebApplicationInitializers detected on classpath
It says that the app is deployed which is correct as the WAR file is extracted and content is present in the appbase directory.
17-Feb-2023 07:40:12.931 INFO [main] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive [/opt/tomcat/webappbackendtest/ROOT.war]
17-Feb-2023 07:40:15.800 INFO [main] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
17-Feb-2023 07:40:15.812 INFO [main] org.apache.catalina.core.ApplicationContext.log 1 Spring WebApplicationInitializers detected on classpath
17-Feb-2023 07:40:15.852 INFO [main] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [/opt/tomcat/webappbackendtest/ROOT.war] has finished in [2,921] ms
Not able to debug why only one app is deployed and not the other and no specific error message present in the logs. What can be missing?
Related
have un problem connection data base with spring boot
I'm the sequel of a developer that is already working. I've been provided the sources but I can't launch the Spring Boot Java project with IntelliJ. I use a sever Xampp for my dataBase. But I have the following error
:: Spring Boot :: (v2.3.3.RELEASE)
2020-12-15 16:39:28.411 INFO 2384 --- [ main] c.a.myapp.myappApplication : Starting myappApplication on DESKTOP-DRP2JSE with PID 2384 (C:\Users\Admin\Downloads\myapp 2.0 Final\myappBack 2.0 - Final\myappBack\out\production\myappBack started by Admin in C:\Users\Admin\Downloads\myapp 2.0 Final\myappBack 2.0 - Final\myappBack)
2020-12-15 16:39:28.415 INFO 2384 --- [ main] c.a.myapp.myappApplication : No active profile set, falling back to default profiles: default
2020-12-15 16:39:29.382 INFO 2384 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFERRED mode.
2020-12-15 16:39:29.496 INFO 2384 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 108ms. Found 8 JPA repository interfaces.
2020-12-15 16:39:30.032 INFO 2384 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-12-15 16:39:30.040 INFO 2384 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-12-15 16:39:30.040 INFO 2384 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.37]
2020-12-15 16:39:30.396 INFO 2384 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-12-15 16:39:30.396 INFO 2384 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1922 ms
2020-12-15 16:39:30.498 WARN 2384 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
2020-12-15 16:39:30.500 INFO 2384 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2020-12-15 16:39:30.513 INFO 2384 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-12-15 16:39:30.519 ERROR 2384 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
Process finished with exit code 1
server.port=8081
server.servlet.session.timeout=1200
# JDBC URL of the database.
spring.datasource.url=jdbc:mysql://localhost:3306/myapp?zeroDateTimeBehavior=CONVERT_TO_NULL&serverTimezone=UTC
# Login username of the database.
spring.datasource.username= root
# Login password of the database.
spring.datasource.password=
# Fully qualified name of the JDBC driver. Auto-detected based on the URL by default.
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# Whether to enable logging of SQL statements.
spring.jpa.show-sql=true
# DDL mode. This is actually a shortcut for the "hibernate.hbm2ddl.auto" property. Defaults to "create-drop" when using an embedded database and no schema manager was detected. Otherwise, defaults to "none".
spring.jpa.hibernate.ddl-auto=update
# Additional native properties to set on the JPA provider.
spring.jpa.database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.properties.hibernate.storage.storage_engine=innodb
# Avoid to restart server (only during dev phase) if DevTools are uninstall
# spring.thymeleaf.cache=false
# spring.security.user.name="root"
# spring.security.user.password="123"
spring.resources.add-mappings=true
The problem is written Reason: Failed to determine a suitable driver class. Classloader can not find driver-class-name in you classpath. Maybe missing MySQL library definition in the maven / gradle configuration.
Maven:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
Gradle:
runtimeOnly 'mysql:mysql-connector-java'
If MySQL library is existed, try to change driver-class-name definition as below.
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
... instead of
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
it works, just force to reload the maven dependency and is ok;
just warning to fix
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/Admin/Downloads/myapp%202.0%20Final/myappBack%202.0%20-%20Final/myappBack/target/myappService/WEB-INF/lib/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/Admin/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
Check your mysql-connector-java version jar
if it's 5 it should be
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
if its 8 it should be
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
Also I don't think you should have spaces after equal sign where is your username and password
Try and remove the spring.datasource.class-name property from the config file.
The url should be good enough to tell which classname is to be used.
Also set "logging.level.root=debug" in the properties to get some more details. See if that helps.
So far I was using Postgres on my localhost to run as my DB. Everything was ok, I had this dependency in my pom.xml and the following config (note that I didn't have the Driver specified explicitely):
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
application.configuration:
spring.datasource.url=jdbc:postgresql://*********
spring.datasource.username=********
spring.datasource.password=*********
All good:
2020-10-31 13:47:03.078 INFO 28600 --- [ task-1] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL10Dialect
2020-10-31 13:47:04.037 INFO 28600 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8091 (http) with context path ''
2020-10-31 13:47:04.270 INFO 28600 --- [ task-1] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2020-10-31 13:47:04.283 INFO 28600 --- [ task-1] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-10-31 13:47:04.659 INFO 28600 --- [ main] DeferredRepositoryInitializationListener : Triggering deferred initialization of Spring Data repositories…
2020-10-31 13:47:04.915 INFO 28600 --- [ main] DeferredRepositoryInitializationListener : Spring Data repositories initialized!
2020-10-31 13:47:04.925 INFO 28600 --- [ main] c.a.u.f.FetcherserviceApplication : Started FetcherserviceApplication in 8.87 seconds (JVM running for 10.334)
Now I wanted to switch to an oracle DB, so I've deleted the above postgresql dependency from my pom.xml and added one for Oracle plus deleted the postgres lines from my configuration and added the following:
spring.datasource.url=jdbc:oracle:thin:#********
spring.datasource.username=********
spring.datasource.password=*********
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
spring.jpa.datasbase-platform=org.hibernate.dialect.Oracle10gDialect
spring.jpa.hibernate.ddl-auto=update
Now, if at this point I try to rerun the application I see that the Oracle Driver is being picked up but then the application still fails to start after because:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-10-31 14:29:30.746 ERROR 6384 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to bind properties under '' to com.zaxxer.hikari.HikariDataSource:
Property: driver-class-name
Value: org.postgresql.Driver
Origin: "driverClassName" from property source "source"
Reason: Failed to load driver class org.postgresql.Driver in either of HikariConfig class loader or Thread context classloader
Action:
Update your application's configuration
Where is this coming from? I did updated the configuration as described above but more importantly the project shouldn't even know at this point that Postgres ever existed as as I've purged it from the pom.xml. So how is it possible there is an issue with it here?
I assume there is still something I don't understand about how Maven manages dependencies.
Thanks!
/András
This is due to the maven unable to import oracle dependencies automatically. Following will help you to resolve the issue
Remove PostgreSQL dependencies from the pom.xml
Then add oracle JDBC dependencies to the pom.xml
https://mvnrepository.com/artifact/com.oracle/ojdbc14
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.4.0</version>
</dependency>
Download oracle dependencies and install manually to maven local repository
mvn install:install-file -Dfile="Your downloaded oracle jar file location" -DgroupId=com.oracle.ojdbc -DartifactId="artifact id" -Dversion="downloaded version number" -Dpackaging=jar
Then clean your project and run. It seemed to work.
You should use the latest 19.8 JDBC driver. Refer to this guide for more details.
Also, you can use DataSourceSample.java to verify if everything works fine.
<dependencies>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8-production</artifactId>
<version>19.8.0.0</version>
<type>pom</type>
</dependency>
</dependencies>
the springboot default log is something like following:
2020-04-06 19:34:11.323 INFO 19308 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-04-06 19:34:11.323 INFO 19308 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.30]
2020-04-06 19:34:11.424 INFO 19308 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-04-06 19:34:11.424 INFO 19308 --- [ restartedMain] o.s.web.context.ContextLoader : Root WebApplicationContext: initializ
And I wrote a logback-spring.xml for setting some logger and appender for my application. However, when the logback-spring.xml exists in "resources" directory, the springboot default log will disappear. And there is only a <configuration> without any subelement in logback-spring.xml.
I have read the part of springboot document which is about logging and got the file. But I don't know how to use it...I tried to copy the element <property name="CONSOLE_LOG_PATTERN ... into my logback-spring.xml and using it as the formatter of my appender, then attaching the appender to <root>. But it can't work.
Thanks.
You need to include the base configuration in your logback-spring.xm file.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration>
<configuration scan="true">
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<logger name="your.application.package" level="DEBUG"/>
</configuration>
I have been trying to host Spring Boot application on WebSphere server.
Versions :
SpringBoot 2.1.6.RELEASE
WebSphere Liberty 19.0.0.6 with JavaEE 8
webjars-locator 0.36
The app was successfuly deployed on standalone Tomcat 9.0.22 and webjars could be resolved there. However for WebSphere I receive an error when trying to access webjars from html page :
2019-08-05 10:43:11.839 DEBUG 1 --- [ecutor-thread-6] o.s.web.servlet.DispatcherServlet : GET "/appcontext/webjars/jquery/jquery.min.js", parameters={}
2019-08-05 10:43:11.845 DEBUG 1 --- [ecutor-thread-6] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped to ResourceHttpRequestHandler ["classpath:/META-INF/resources/webjars/"]
2019-08-05 10:43:11.849 DEBUG 1 --- [ecutor-thread-6] o.s.w.s.r.ResourceHttpRequestHandler : Resource not found
2019-08-05 10:43:11.849 DEBUG 1 --- [ecutor-thread-6] o.s.web.servlet.DispatcherServlet : Completed 404 NOT_FOUND
And the webjars pattern was successfuly mapped by Spring :
2019-08-05 10:43:09.039 DEBUG 1 --- [ecutor-thread-6] o.s.w.s.handler.SimpleUrlHandlerMapping : Patterns [/webjars/**, /**] in 'resourceHandlerMapping'
The solution for this is to add classloading entry, with useJarUrls attribute set to true, to WebSphere server.xml file :
<server description="myServer">
<featureManager>
<feature>servlet-3.0</feature>
</featureManager>
<classloading useJarUrls="true"/> <!-- this line was added -->
<httpEndpoint httpPort="9080" httpsPort="9443" host="*" id="defaultHttpEndpoint"/>
</server>
This IBM support issue was particulary helpful in solving this problem.
I am setting up a Configuration manager using Spring cloud config, I'm having an issue where the Client is not picking up the property source (Hosted HTTPS Server URI) when I deploy the application to a Docker container on Azure, works when the same code is running on Localhost which picks the same URI, thoughts on how to proceed ?
I have provided all the required parameters including the app name and the SERVER URI along with the active profile (dev) and label (1.0) in the bootstrap.properties, I also tried disabling security by setting management.security.enabled to false thinking it is a Security issue, but nothing seems to locate the property source. (Worst case is the HTTPS server URI seems to be located when the client is running locally), It is only when the code is containerized using Docker and deployed to Azure, it is showing this behavior. Any help greatly appreciated !
P.S - Working on latest snapshots of SpringBoot 2.1.3 and latest snapshot of Spring Cloud starter 2.1.1, No problems with any of the dependencies I have added.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.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>
<org.apache.commons.version>3.5</org.apache.commons.version>
<java.version>1.8</java.version>
<lombok.version>1.16.12</lombok.version>
<apt.version>1.1.3</apt.version>
<querydsl.version>4.1.4</querydsl.version>
<log4j-api.version>2.6</log4j-api.version>
</properties>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
<version>2.1.1.RELEASE</version>
</dependency>
bootstrap.properties
spring.cloud.config.uri=example.org
spring.application.name=MyApp
spring.profiles.active=dev
spring.cloud.config.profile=dev
spring.cloud.config.label=1.0
application.properties
management.endpoints.web.exposure.include=*
Expected when running on Localhost
2019-04-03 14:48:42.499 INFO 50217 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : example.org
2019-04-03 14:48:43.961 INFO 50217 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Located environment: name=MyApp, profiles=[dev], label=1.0, version=null, state=null
2019-04-03 14:48:43.961 INFO 50217 --- [ main] b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource {name='configService', propertySources=[MapPropertySource {name='MyApp-dev'}]}
2019-04-03 14:48:43.965 INFO 50217 --- [ main] c.s.c.backroom.claims.ClaimsApplication : The following profiles are active: dev
2019-04-03 14:48:44.985 INFO 50217 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-04-03 14:48:45.135 INFO 50217 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 138ms. Found 17 repository interfaces.
2019-04-03 14:48:45.929 INFO 50217 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=1f523ae6-9bf7-3733-ae13-ea87a67e1564
201
Actual Result when running on Docker container on Azure
2019-04-03T17:35:03.470926214Z 2019-04-03 17:35:03.470 INFO 8 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : example.org
2019-04-03T17:35:09.723760869Z 2019-04-03 17:35:09.723 WARN 8 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Could not locate PropertySource: Could not extract response: no suitable HttpMessageConverter found for response type [class org.springframework.cloud.config.environment.Environment] and content type [text/html;charset=ISO-8859-1]
2019-04-03T17:35:09.752928427Z 2019-04-03 17:35:09.752 INFO 8 --- [ main] c.s.c.backroom.claims.ClaimsApplication : The following profiles are active: dev
2019-04-03T17:35:19.974721803Z 2019-04-03 17:35:19.971 INFO 8 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.