We have a Spring application deployed on tomcat, and it does not start.
The application error is as follows:
Caused by: org.springframework.beans.PropertyBatchUpdateException; nested
PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [${hibernate.connection.driver_class}]
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:121)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:75)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1564)
... 49 more
We do have a properties file defined at:
/opt/tomcat/appname/tomcat8-2
with three files: config.properties, core-ws.proprties, and log4j-config.xml
We know ${TOMCAT_CONFIG_HOME} is defined to be: /opt/tomcat/appname/tomcat8-2
We know that the file permissions are correct, the user running tomcat has read permissions to the directories and files in this config directory. I can as that tomcat user edit/read the properties file. So, we know it's not a permissions issue.
From the app log, we have this error message:
Skipped XML bean definition file due to specified profiles [default] not matching: class path resource [spring/app-platform-entity-context.xml]
The Spring application context file has this for properties:
<beans profile="default">
<context:property-placeholder location="file:${TOMCAT_CONFIG_HOME}/core-ws.properties" />
</beans>
Finally here is what the core-ws.properties looks like:
hibernate.connection.url=jdbc:oracle:thin:#//123.456.789/APP_DB
hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver
hibernate.connection.username=some_db_user
hibernate.connection.password=some_db_password
So, I have looked into this for a coupe of days, and I am at my wits end. I can tell you we have no problem with the log4j-config.xml file. The app can find it, and read it just fine. it is just this one parameter that seems to be crashing the app ...
Any help with this matter would be much appreciated. Thanks!
The reason that XML file was skipped was because we had a -Dspring.profiles.active=prod in our CATALINA_OPTS setup.
We didn't find it until we started exporting what the values were as tomcat started.
Once we removed this line, our [default] profile tookover as it should.
Thanks!
Answering this for stand-alone apps:
In my case it was because of the order of setting up ApplicationContext, I was loading the xml file, before setting the profile.
The correct order is:
GenericXmlApplicationContext ctx =
new GenericXmlApplicationContext();
ctx.getEnvironment().setActiveProfiles("dev");
ctx.load("com/profiles/*-config.xml");
ctx.refresh();
Related
I am having trouble to use external configuration properties for my Quarkus application.
I want to override the database properties. The application.properties inside the project has properties for dev and test, not for prod. The values for prod are inside the external application.properties.
I read the official guide (https://quarkus.io/guides/config#overriding-properties-at-runtime) and tried to place an application.properties file in a folder next to the runner-jar called config. That didn't work. But just passing the properties on the command line didn't work either.
C:.
│ 0.1.0-SNAPSHOT-runner.jar
│ 0.1.0-SNAPSHOT.jar.original
│
├───config
│ application.properties
Internal:
%dev.quarkus.datasource.jdbc.url=jdbc:postgresql://localhost:5432/postgres
%dev.quarkus.datasource.username=postgres
%dev.quarkus.datasource.password=postgres
%dev.quarkus.datasource.db-kind=postgresql
%dev.quarkus.hibernate-orm.database.generation=none
%test.quarkus.datasource.jdbc.url=jdbc:h2:mem:test
%test.quarkus.datasource.username=sa
%test.quarkus.datasource.password=
%test.quarkus.datasource.db-kind=h2
%test.quarkus.hibernate-orm.database.generation=none
External:
quarkus.datasource.jdbc.url=jdbc:postgresql://localhost:5432/postgres
quarkus.datasource.username=postgres
quarkus.datasource.password=postgres
quarkus.datasource.db-kind=postgresql
quarkus.hibernate-orm.database.generation=none
With java -jar .\0.1.0-SNAPSHOT-runner.jar I get the following error:
2020-07-24 16:58:16,666 ERROR [io.qua.application] (main) Failed to start application: java.lang.IllegalArgumentException: Parameter 'dataSource' may not be null
at org.wildfly.common.Assert.checkNotNullParamChecked(Assert.java:71)
at org.wildfly.common.Assert.checkNotNullParam(Assert.java:49)
at org.wildfly.security.auth.realm.jdbc.QueryConfiguration.<init>(QueryConfiguration.java:40)
at org.wildfly.security.auth.realm.jdbc.QueryBuilder.buildQuery(QueryBuilder.java:76)
at org.wildfly.security.auth.realm.jdbc.JdbcSecurityRealmBuilder.build(JdbcSecurityRealmBuilder.java:51)
at io.quarkus.elytron.security.jdbc.JdbcRecorder.createRealm(JdbcRecorder.java:42)
at io.quarkus.deployment.steps.ElytronSecurityJdbcProcessor$configureJdbcRealmAuthConfig-173765586.deploy_0(ElytronSecurityJdbcProcessor$configureJdbcRealmAuthConfig-173765586.zig:76)
at io.quarkus.deployment.steps.ElytronSecurityJdbcProcessor$configureJdbcRealmAuthConfig-173765586.deploy(ElytronSecurityJdbcProcessor$configureJdbcRealmAuthConfig-173765586.zig:36)
at io.quarkus.runner.ApplicationImpl.doStart(ApplicationImpl.zig:524)
at io.quarkus.runtime.Application.start(Application.java:90)
at io.quarkus.runtime.ApplicationLifecycleManager.run(ApplicationLifecycleManager.java:91)
at io.quarkus.runtime.Quarkus.run(Quarkus.java:61)
at io.quarkus.runtime.Quarkus.run(Quarkus.java:38)
at io.quarkus.runtime.Quarkus.run(Quarkus.java:106)
at io.quarkus.runner.GeneratedMain.main(GeneratedMain.zig:29)
2020-07-24 16:58:16,730 ERROR [io.qua.run.Application] (main) Error running Quarkus application: java.lang.RuntimeException: Failed to start quarkus
at io.quarkus.runner.ApplicationImpl.doStart(ApplicationImpl.zig:649)
at io.quarkus.runtime.Application.start(Application.java:90)
at io.quarkus.runtime.ApplicationLifecycleManager.run(ApplicationLifecycleManager.java:91)
at io.quarkus.runtime.Quarkus.run(Quarkus.java:61)
at io.quarkus.runtime.Quarkus.run(Quarkus.java:38)
at io.quarkus.runtime.Quarkus.run(Quarkus.java:106)
at io.quarkus.runner.GeneratedMain.main(GeneratedMain.zig:29)
Caused by: java.lang.IllegalArgumentException: Parameter 'dataSource' may not be null
at org.wildfly.common.Assert.checkNotNullParamChecked(Assert.java:71)
at org.wildfly.common.Assert.checkNotNullParam(Assert.java:49)
at org.wildfly.security.auth.realm.jdbc.QueryConfiguration.<init>(QueryConfiguration.java:40)
at org.wildfly.security.auth.realm.jdbc.QueryBuilder.buildQuery(QueryBuilder.java:76)
at org.wildfly.security.auth.realm.jdbc.JdbcSecurityRealmBuilder.build(JdbcSecurityRealmBuilder.java:51)
at io.quarkus.elytron.security.jdbc.JdbcRecorder.createRealm(JdbcRecorder.java:42)
at io.quarkus.deployment.steps.ElytronSecurityJdbcProcessor$configureJdbcRealmAuthConfig-173765586.deploy_0(ElytronSecurityJdbcProcessor$configureJdbcRealmAuthConfig-173765586.zig:76)
at io.quarkus.deployment.steps.ElytronSecurityJdbcProcessor$configureJdbcRealmAuthConfig-173765586.deploy(ElytronSecurityJdbcProcessor$configureJdbcRealmAuthConfig-173765586.zig:36)
at io.quarkus.runner.ApplicationImpl.doStart(ApplicationImpl.zig:524)
... 6 more
With java -Dquarkus.datasource.jdbc.url=jdbc:postgresql://localhost:5432/postgres -Dquarkus.datasource.username=postgres -Dquarkus.datasource.password=postgres -Dquarkus.datasource.db-kind=postgresql -jar .\0.1.0-SNAPSHOT-runner.jar I get this:
Error: Could not find or load main class .datasource.jdbc.url=jdbc:postgresql:..localhost:5432.postgres
Caused by: java.lang.ClassNotFoundException: /datasource/jdbc/url=jdbc:postgresql://localhost:5432/postgres
I could only find two similar threads (How can I override properties in Quarkus? and https://github.com/quarkusio/quarkus/issues/1218). Both mention the method with the application.properties in the config folder. Since this does not work for me and I cannot find any new information, I am somewhat lost ...
I would be grateful for any help!
Ok, so it turns out there are several properties which you can not override at runtime. Those are marked on the offical overview of all properties (https://quarkus.io/guides/all-config). There is a little hint about this at the top of the page.
quarkus.datasource.db-kind is one of those properties. So all I had to do is include this property in my main application.properties. After that the external file was found and I could use those values for url, password, and username.
Max is right when he says that quarkus.datasource.db-kind is a runtime property.
The only way I got it to work so that I have
%dev
quarkus.datasource.db-kind=postgres
%qa
quarkus.datasource.db-kind=h2
%prod
quarkus.datasource.db-kind=<otherDBKind>
is to, either use profiling:
gradle/maven quarkusDev -Dquarkus-profile=[dev,qa,prod]
or, if you want to deploy the application and run it through java -jar, you have to compile it with the profile context
gradle/maven quarkusBuild -Dquarkus-profile=[dev,qa,prod]
a build for each profile with a different db-kind
I am getting following exception while running a spring boot application :
Failed to bind properties under 'cluster' to com.datastax.driver.core.Cluster:
Property: cluster
Value:
Origin: "cluster" from property source "class path resource [application.yml]"
Reason: No converter found capable of converting from type [java.lang.String] to type [com.datastax.driver.core.Cluster]
Action:
Update your application's configuration
The configuration file is being read from consul. So, as seen from the error description, the value of the property 'cluster' is found empty. But config as seen the file, looks like :
cassandra:
host: abc:50126
forceSchemaCreation: false
cluster:
name: test_cluster
user: test_user
password: password
defaultFetchSize: 10000
callback.executor.pool: 10
Can there be a syntactical error in the yml file?
Or
Why does error say 'cluster' instead of 'cassandra.cluster'? Is is right to doubt this part?
Or
The 'Origin' part in the description points to 'class path resource [application.yml]'. THis should be a concern?
Also, because I was getting 'Command line too long' message while running the application, I set 'dynamic.classpath' to true in workspce file.
Can there be a syntactical error in the yml file?
I don't see any error in the yml file.
Why does error say 'cluster' instead of 'cassandra.cluster'?
The 'Origin' part in the description points to 'class path resource [application.yml]'. This should be a concern?
Please check if you are using #ConfigurationProperties over your Configuration class. If yes, please try removing it, if not needed. Just #Configuration would be good to autowire all your global properties in the yml.
Hi have a tomcat server with a web app in that is supposed to connect to a MySQL database.
The driver is loaded when I use -verbose:class
[Loaded com.mysql.jdbc.Driver from file:/app/tomcat/8.5.4/webapps/my-app/WEB-INF/lib/mysql-connector-java-5.1.36.jar]
But for some reason it's still throwing me an exception when loading spring context:
Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.RuntimeException: Could not load class of driverClassName com.mysql.jdbc.Driver
I tried to move the connector lib file to tomcat lib folder, but it didn't change anything. I tried different versions of the connector still same issue.
I can't find out what exactly problem is without your code files: but i can guess, due to this problems it throws this kinda Exception.
Possible solution, there's some mistake in database property file.
This is some property, you can check, give database name and username password according to your system. The problem occurs due to single . or , or ; too.. You can find more detail here.
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost/mydb
jdbc.username=myinfuser
jdbc.password=myinfuserpw
I tried to deploy a Vaadin hello world application in JBOSS. The application is as simple as it can be.
My development environment is eclipse for java EE + tomcat
java.lang.RuntimeException: Error configuring property: includeWebInfInClasspath for WarClassLoaderDeployer
at org.jboss.kernel.plugins.dependency.ConfigureAction.dispatchSetProperty(ConfigureAction.java:112)
at org.jboss.kernel.plugins.dependency.ConfigureAction.setAttributes(ConfigureAction.java:85)
(...)
Caused by: java.lang.IllegalArgumentException: No such property includeWebInfInClasspath for bean org.jboss.web.tomcat.service.deployers.WarClassLoaderDeployer available [java2ClassLoadingCompliance, parentFirst, requiredInputs, filteredPackages, allInputs, deploymentRegistry, class, stage, wantComponents, componentsOnly, input, inputs, relativeOrder, output, useUnitName, outputs, topLevelOnly]
I have tried to google this error with no success.
Does anyone have any clues?
Is it a web server configuration or my *.war is missing something?
EDIT:
This error occur when I start the server after placing my *.war in the folder.
My JBOSS version is 5
I guess, you're using an old JBoss 5.
The WarClassLoaderDeployer is configured in the file server/default/deployers/jbossweb.deployer/META-INF/war-deployers-jboss-beans.xml. (The 'default' directory should be changed to whatever you passed as -c parameter) Open the file, find the WarClassLoaderDeployer bean and drop the line defining the property with name includeWebInfInClasspath.
I'm struggling to set connect a Java program to MySQL using JPA/Hibernate.
I'm currently getting the following error when I try to call createEntityManagerFactory():
[main] ERROR org.hibernate.connection.DatasourceConnectionProvider - Could not find datasource: java:jdbc/myDataDS
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:75)
Googling seems to indicate that I need a jndi.properties file in META-INF in my classpath, but I can't seem to find any information about what that file should contain in my case.
Edit: I'm running this stand-alone, for the time being.
A jndi.properties file should be at the root of the classpath and typically contains the URL of the JNDI server and the initial context factory to use. For example, with JBoss:
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=jnp://localhost:1099
But, when using Hibernate, you should actually declare these properties in the hibernate.cfg.xml. For example, with WebLogic:
<property name="jndi.class">weblogic.jndi.WLInitialContextFactory</property>
<property name="jndi.url">t3://127.0.0.1:7001</property>