we are using
quarkus.application.timestamp=${maven.build.timestamp} in properties file and trying to access the timestamp in java class by:
#ConfigProperty(name = "quarkus.application.timestamp")
String buildTime;
But the deployment is failing due to this
Related
I am trying to connect an application with VisualVM, but VisualVM unable to connect with application: Below is the env:
JBoss EAP 7.3
Java 11
OpenShift
I have tried to configure it in different ways, but all failed:
Config try 1:
Use few env variables in script file, so that it could execute first (file contents are mentioned below):
echo *** Adding system property for VisulVM ***
batch
/system-property=jboss.modules.system.pkgs:add(value="org.jboss.byteman,com.manageengine,org.jboss.logmanager")
/system-property=java.util.logging.manager:add(value="org.jboss.logmanager.LogManager")
run-batch
I can see that above commands executed successfully and above properties are available in JBoss config (I verified using Jboss cli command).
JAVA_TOOLS_OPTIONS: -agentlib:jdwp=transport=dt_socket,server=y,address=8000,suspend=n -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=3000 -Dcom.sun.management.jmxremote.rmi.port=3001 -Djava.rmi.server.hostname=127.0.0.1 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Xbootclasspath/a:/opt/eap/modules/system/layers/base/org/jboss/log4j/logmanager/main/log4j-jboss-logmanager-1.2.0.Final-redhat-00001.jar -Xbootclasspath/a:/opt/eap/modules/system/layers/base/org/jboss/logmanager/main/jboss-logmanager-2.1.14.Final-redhat-00001.jar
Result:
- java.lang.RuntimeException: WFLYCTL0079: Failed initializing module org.jboss.as.logging
- Caused by: java.util.concurrent.ExecutionException: java.lang.IllegalStateException: WFLYLOG0078: The logging subsystem requires the log manager to be org.jboss.logmanager.LogManager. The subsystem has not be initialized and cannot be used. To use JBoss Log Manager you must add the system property "java.util.logging.manager" and set it to "org.jboss.logmanager.LogManager"
Config 2:
JAVA_TOOL_OPTIONS= -agentlib:jdwp=transport=dt_socket,server=y,address=8000,suspend=n -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=3000 -Dcom.sun.management.jmxremote.rmi.port=3001 -Djava.rmi.server.hostname=127.0.0.1 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.util.logging.manager=org.jboss.logmanager.LogManager -Djboss.modules.system.pkgs=org.jboss.byteman,org.jboss.logmanager -Xbootclasspath/a:/opt/eap/modules/system/layers/base/org/jboss/log4j/logmanager/main/log4j-jboss-logmanager-1.2.0.Final-redhat-00001.jar -Xbootclasspath/a:/opt/eap/modules/system/layers/base/org/jboss/logmanager/main/jboss-logmanager-2.1.14.Final-redhat-00001.jar
Result:
WARNING: Failed to instantiate LoggerFinder provider; Using default.
java.lang.IllegalStateException: The LogManager was not properly installed (you must set the "java.util.logging.manager" system property to "org.jboss.logmanager.LogManager")
Config 3:
• Modify in standalone.conf, where I put all required configuration in this file.
Result:
WARNING: Failed to instantiate LoggerFinder provider; Using default.
java.lang.IllegalStateException: The LogManager was not properly installed (you must set the "java.util.logging.manager" system property to "org.jboss.logmanager.LogManager")
Kindly suggest that what is the correct configurations?
I am following the developer guide to deploy SCDF to a minikube cluster on my local machine. Used the helm chart approach. Was able to get it working with the defaults. The default deploys a mariadb in the cluster. I wanted to change it to use an external mysql db that is running in a docker container in my machine (outside the cluster). Followed the recommendations to change the values.yaml to enable the external DB and attributes for external DB connection (URI, dbname, user/pwd etc.).
Then deployed using "helm install my-release -f values.yaml bitnami/spring-cloud-dataflow"
The SCDF pod (& skipper pod) errors out because it can't find the mysql jdbc driver. kubectl logs on the pods show the following error: "java.lang.IllegalStateException: Cannot load driver class: com.mysql.cj.jdbc.Driver"
How do I include the mysql jdbc driver in the image for SCDF that gets deployed (or resolve this problem). I read SCDF already includes the drivers for std databases (true ?). New to helm/k8s so apologies if solution is obvious... Other posts on similar error all talk about including this in the pom.xml . But this is not a dependency issue with my (task) app but SCDF itself.
thanks
-------------------- more detail on the exception stack ---------------
Caused by: 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 java.lang.IllegalStateException: Cannot load driver class: com.mysql.cj.jdbc.Driver
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:657)
...
Looks like I just need to specify the mariadb jdbc driver in the values.yaml file for mysql as well. That got past the load class error.
But still would like to know how to prevent class load error for a different driver specified when SCDF is deployed to k8s via the helm chart.
I'm having a little problems running JUnit tests from Eclipse directly (using the "Run As JUnit test" on the JUnit test file I want to run) on a simple Spring Boot application.
I'm using Gradle as a build tool. Now, when running the test as a Gradle task it works just fine, but when running it as an Eclipse JUnit task it fails with the follwoing error
java.lang.IllegalStateException: Failed to load ApplicationContext
...
Caused by: org.springframework.beans.factory.BeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath.
My application.properties files does define a local MySQL database and that seems to work fine with gradle:
spring.datasource.url: jdbc:mysql://localhost:3306/test
spring.datasource.username=user
spring.datasource.password=pass
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.jpa.hibernate.ddl-auto=update
My Application Class:
#SpringBootApplication
public class Application {
My Application test:
#RunWith(SpringJUnit4ClassRunner.class)
#SpringApplicationConfiguration(classes = Application.class)
#WebAppConfiguration
public class ApplicationTests {
Any ideas?
My Java EE 7 app, which uses Spring, runs on Tomcat 7. It accesses a database by using a JNDI datasource, defined by this line in context.xml:
<Resource auth="Container" driverClassName="org.postgresql.Driver" maxActive="100" maxIdle="30" maxWait="10000" name="jdbc/leadmanager" password="xxxxxxxx" type="javax.sql.DataSource" url="jdbc:postgresql://localhost:5432/leadmanager" username="postgres"/>
I created some JUnit tests. When I tried to run them (in Eclipse, by right-clicking the test class and selecting Run As | JUnit Test), an exception occurred:
javax.persistence.PersistenceException: [PersistenceUnit: leadmanager] Unable to build EntityManagerFactory
...
Caused by: org.hibernate.service.jndi.JndiException: Error parsing JNDI name [java:/comp/env/jdbc/leadmanager]
...
Caused by: 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
...
Thanks to this helpful post -- https://blogs.oracle.com/randystuph/entry/injecting_jndi_datasources_for_junit -- I found a solution. I added this to my test class:
#BeforeClass
public static void setUpClass() throws Exception {
// create initial context
System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory");
System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming");
InitialContext ic = new InitialContext();
ic.createSubcontext("java:");
ic.createSubcontext("java:/comp");
ic.createSubcontext("java:/comp/env");
ic.createSubcontext("java:/comp/env/jdbc");
PGPoolingDataSource ds = new PGPoolingDataSource();
ds.setServerName("localhost:5432/leadmanager");
ds.setUser("postgres");
ds.setPassword("xxxxxxxx");
ic.bind("java:/comp/env/jdbc/leadmanager", ds);
}
But that's hideous! I'm forced to define my datasource twice, once in context.xml and again in my test class. And I'm forced to store my database password in Java code that's going to be checked in to source control.
I've already consulted this post, as well: Setting up JNDI Datasource in jUnit
Is there a better way?
The reason is that your test is not running inside tomcat, but runs in a separate instance of JVM.
Try to build your unit test using Arquillian - this tool will package your test as a simple web application, which is executed within your tomcat. The result is that everything, what is accessible in tomcat, will be accessible in your tests, including resources.
You can also use TomcatJNDI. It reads Tomcat's configuration files and creates a JNDI environment as in your web application. It is as easy as this code example:
TomcatJNDI tomcatJNDI = new TomcatJNDI();
tomcatJNDI.processContextXml(contextXmlFile);
tomcatJNDI.start();
Now you can access all your resources you have declared in Tomcat's configuration files.
Find out more about it here.
I generated a .war file for my SpringMVC + Maven + Hibernate + MySQL app which was working perfectly fine on localhost and local MySQL database. The way I configure the database is through a WebAppConfig.java file which looks at an application.properties file and retrieves the appropriate information.
Then I created an OpenShift account and deployed that .war file. I added MySQL and PHPMyAdmin cartridges so I can maintain a database. When I try to retrieve information or push to the database through my application I receive this error.
HTTP Status 500 - Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Could not open connection
message Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Could not open connection
exception org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Could not open connection
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:948)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838)
javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
I already added the appropriate information for my database in my properties file so I don't think that is the issue.
application.properties
#DB
db.driver = com.mysql.jdbc.Driver
db.url = jdbc:mysql://{OPENSHIFT_MYSQL_DB_HOST}:{OPENSHIFT_MYSQL_DB_PORT}/springmvc
db.username = {OPENSHIFT_MYSQL_DB_USERNAME}
db.password = {OPENSHIFT_MYSQL_DB_PASSWORD}
#Hibernate
hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
hibernate.show_sql = true
entitymanager.packages.to.scan = org.example.app.model
hibernate.cache.provider_class = org.hibernate.cache.NoCacheProvider
Note: In my actual code I have the actual OPENSHIFT_MYSQL_DB_HOST and OPENSHIFT_MYSQL_DB_PORT values not those placeholders!
I forgot to actually answer this question.
I just want to clarify once again that using the 'OPENSHIFT' variables rather than putting the ACUTAL values in the application.properties fixed the issue.
db.url = jdbc:mysql://${OPENSHIFT_DB_HOST}:${OPENSHIFT_DB_PORT}/${OPENSHIFT_APP_NAME}
db.username = ${OPENSHIFT_MYSQL_DB_USERNAME}
db.password = ${OPENSHIFT_MYSQL_DB_PASSWORD}
Make sure mysql cartridge is up and running; if need be try restarting it. Otherwise, please post your properties file. Also please read the following threads, it may be of help:
https://www.openshift.com/forums/openshift/hibernate-mysql-connection-failing
https://www.openshift.com/forums/openshift/mysql-db-stops-responding-after-some-time
Thanks for posting to our forums as well:
https://www.openshift.com/forums/openshift/openshift-app-cant-connect-to-mysql-jdbcconnectionexception-could-not-open
Looks like you'll want to use:
db.username = {OPENSHIFT_MYSQL_DB_USERNAME}
db.password = {OPENSHIFT_MYSQL_DB_PASSWORD}
instead of:
db.username = root
db.password = pass
Missing the $ in the variable names, you can also run it locally very easily to make sure it's just the mysql variables and not a coding error.
Have you checked PHPMyAdmin to make sure MYSQL is up has the database and tables you expect and validate all your sql.
Does WebAppConfig have the proper Spring annotations? Does it build fully with no errors? Do your unit tests work? Do you have all the maven dependencies and versions established?
This has worked for me using OpenStack on all their available java server types.
I don't understand why openshift force us to use their environment variables instead of using "localhost:3306" and the actual values for username/password. This is making us very inconvenient. Also, adding this line of code jdbc:mysql://${OPENSHIFT_DB_HOST}:${OPENSHIFT_DB_PORT}/${OPENSHIFT_APP_NAME}
in my application-context.xml gets a compilation error since spring doesn't recognize these values.