logback logging with application.yml fails to lookup the properties - logback

logback is unable to evaluate spring application name
<property scope="context" name="app_name" value="${spring.application.name}" /> log output:"app_name":"spring.application.name_IS_UNDEFINED"
if the property is printed out of the application context, it is working fine.
logback-classic 1.11
logback-core 1.11
logstash-logback-encoder 4.11
UPDATE:
changing logback.xml to logback-spring.xml and adding <springProperty scope="context" name="app_name" source="spring.application.name" />
rather than <property scope="context" name="app_name" value="${spring.application.name}" /> fixed the issue with spring-boot 1.5.4
Thanks

UPDATE: changing logback.xml to logback-spring.xml and adding
rather than fixed the issue with spring-boot 1.5.4

Related

Camel Bindy application JBoss EAP 6.1 Deployment issue

I am trying to deploy a camel application which reads CSV file and process it.I am trying to use camel bindy to unmarshal the csv to POJO.
The camel bindy module was not available in jboss EAP i have added it.
Camel Route:
<?xml version="1.0" encoding="ASCII"?>
<routes xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="switchyard://FileService" />
<log message="inside route" />
<doTry>
<split streaming="true">
<tokenize token="/n"></tokenize>
<unmarshal ref="bindyDataformat" >
<bindy classType="com.agcs.bih.prototypes.filetosca.Student" type="Csv"/>
</unmarshal>
<process ref="ProcessCSV"></process>
</split>
<doCatch>
<exception>java.lang.Exception</exception>
<log message="FileToScaRoute - message received: ${exception.message}" />
</doCatch>
</doTry>
</route>
</routes>
Iam getting the below exception during deployment.
Caused by: java.lang.IllegalArgumentException: Data format 'bindy-csv' could not be created. Ensure that the data format is valid and the associated Camel component is present on the classpath
Attaching server.log
Can you please help
It sounds like you are using JBoss FSW possibly? Fuse 6.3 on EAP 6.3 includes camel-bindy and there's an example included there for SwitchYard as well if you can upgrade.
Please see;
http://camel.apache.org/bindy.html
Make sure you have created bindyDataFormat
<dataFormats>
<bindy id="bindyDataformat" type="Csv" classType="org.apache.camel.bindy.model.Order"/>
</dataFormats>
After refering the link https://developer.jboss.org/thread/177124.I have added the manifest entry in maven jar plugin pom xml
<manifestEntries>
<Dependencies>org.apache.camel.bindy export services</Dependencies>
</manifestEntries>
iam able to unmarshal it to pojo using camel bindy now.

How to prevent database renewing its data in camunda

I am using
- camunda-bpm-wildfly-7.4.0
- mysql-5.6.24-winx64
- wildfly-8.2.1.Final
I have integerated mysql with camunda wildfly.
My datasource code in the standalone.xml is as follows,
<datasource jta="true" jndi-name="java:jboss/datasources/ProcessEngine" pool-name="ProcessEngine" enabled="true" use-java-context="true" use-ccm="true">
<connection-url>jdbc:mysql://localhost:8888/camundabpm?DB_CLOSE_DELAY=-1;MVCC=TRUE;DB_CLOSE_ON_EXIT=FALSE</connection-url>
<driver>mysql</driver>
How do I prevent the database resetting on server restart? It removes all data and replaces it with new data on every server start. So I am unable to persist my data between server on and off.
Update:
I found out that hibernate was deleting the tables from the db So I changed the property from this
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
to
<property name="hibernate.hbm2ddl.auto" value="update" />
after having a look at How to make Hibernate not drop tables. But now the tasklist process instances are removed and only the tables created by my project remain and all other tables are refreshed with new data.
Can you check the value of the databaseSchemaUpdate poroperty? It should be contained in the standalone.xml of our WildFly (very down). Make sure it os not set to create-drop.
See https://docs.camunda.org/manual/7.4/reference/deployment-descriptors/tags/process-engine/#configuration-properties

Creating library jar with other libraries

I am creating jar via eclipse, but not runnable jar, it is just a library. After importing that i'm creating new project and adding this jar file. But when run application it throws exception about not finding libraries which are inside in my jar. But these libraries are included in created jar. Where is my mistake ? How can I do that ?
You cannot, by default, include dependency JAR files inside your JAR file, you need a plugin, as specified in Classpath including JAR within a JAR (suggested by Artur Malinowski). If, however, you wish to create a JAR which simply works with your other dependencies, you can easily do this via Eclipse by right clicking on the project, going into properties, Java Build Path, Libraries and then you can add JARs, etc. by using the buttons along the right side of the menu (as of Kepler).
I hope this helps.
P.S. You'll have to cart round the dependency JAR files wherever you put the main JAR, however, this is the easiest and most straightforward approach to getting it working in the first place, and then refine later, using build plugins.
I found the solution. I write some ant script for creating jar and it was solved my problem.
<target name="dist" depends="build-jar">
<property name="store.jar.name" value="MYJARNAME"/>
<property name="store.dir" value="store"/>
<property name="store.jar" value="${store.dir}/${store.jar.name}.jar"/>
<echo message="Packaging project into a single JAR at ${store.jar}"/>
<mkdir dir="dist"/>
<delete dir="${store.dir}"/>
<mkdir dir="${store.dir}"/>
<mkdir dir="dist/lib"/>
<copy todir="dist/lib/" overwrite="false" granularity="9223372036854">
<fileset dir="lib/"/>
</copy>
<jar destfile="${store.dir}/temp_final.jar" filesetmanifest="skip">
<zipgroupfileset dir="dist" includes="*.jar"/>
<zipgroupfileset dir="dist/lib" includes="*.jar"/>
<manifest>
<attribute name="Main-Class" value="${main.class}"/>
</manifest>
</jar>
<zip destfile="${store.jar}">
<zipfileset src="${store.dir}/temp_final.jar"
excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA"/>
</zip>
<delete file="${store.dir}/temp_final.jar"/>
</target>

connection exception :CannotGetJdbcConnectionException: Could not load JDBC driver class ["com.microsoft.sqlserver.jdbc.SQLServerDriver";]

I have an web application in struts 1.3 which contain hibernate as ORM and spring as contextloaded AOP or as it is in general use.
I'm trying to deploy it in tomcat 6.0 server. earlier it was connected to mysql and it was working fine but now I want to connect it with MS Sql server 2008 so I downloaded "sqljdbc" and "sqljdbc4" jar and placed it into "C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\web1\WEB-INF\lib" location of my system. I have java 7 installed in my system.when I trying to run then its giving exception :
org.apache.jasper.JasperException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/applicationContext-hibernate.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyAccessExceptionsException: PropertyAccessExceptionsException (1 errors); nested propertyAccessExceptions are: [org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not load JDBC driver class ["com.microsoft.sqlserver.jdbc.SQLServerDriver";]; nested exception is java.lang.ClassNotFoundException: "com/microsoft/sqlserver/jdbc/SQLServerDriver";]
My jdbc property file entry is :
jdbc.driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
jdbc.url="jdbc:sqlserver://localhost:1433/databaseName=DB_1"
jdbc.username="dipak";
jdbc.password="";
hibernate.dialect=org.hibernate.dialect.SQLServer2008Dialect
ApplicationContext-Hibernate.xml
entry is :
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
Please help me to solve this problem, I Google a lot and tried many solutions but not get success yet, So any help would be much appreciated.
If you need any other/more information then please let me know.
Thanks,
-Dipak
Wrong spot for that JAR. Tomcat 6 and higher expects to find it in the Tomcat server /lib, not your application WEB-INF/lib. Move it and you'll see better results.
Make sure that your URL syntax is correct:
http://msdn.microsoft.com/en-us/library/ms378428(v=sql.90).aspx

Do I need DataSource in JPA Hibernate project?

I am preparing some application with usage of JPA 2.0, Hibernate as provider, MySQL 5 as database, which will be deployed on JBoss AS 7.0.2.I have already configured some basics in persistence.xml and I came into some kind of trouble. I have noticed that some people also defines some specific DataSource on JBoss Management Console level.
My question is. Do I really need to worry about some DataSource or anything like that in Hibernate application?I thought it is important in old JDBC approach.In some books, where examples are shown, there is no such configuration in persistence.xml or hibernate.cfg.xml
Do I have to place mysql connector into JBOSS_HOME/standalone/deployments directory to use MySQL in my application?Here is content of my persistence.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="SomeApp">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/somedb" />
<property name="hibernate.connection.username" value="" />
<property name="hibernate.connection.password" value="" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
</properties>
</persistence-unit>
</persistence>
Well, you can either access the database by:
providing the url/driver/password/etc. information in the persistence.xml using your jpa-provider properties (in your case hibernate.connection.*) or the JPA 2.0 standardised javax.persistence.jdbc.* ones - this basically looks like the example you've posted,
creating a Data Source in the ApplicationServer and just referring to it in the persistence.xml (through it's JNDI name you provide during creation) which might look similar to this (without the XML schema definition for the sake of brevity) :
<persistence>
<persistence-unit name="SomeApp">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/myDB</jta-data-source>
</persistence-unit>
</persistence>
What you're actually doing right now (with these properties) is using the JDBC.
I would definitely go with the creation of the Data Source in the ApplicationServer rather than providing it in the properties in persistence.xml. It allows you to dynamically change the end-database, it's type, credentials, manage connection pools, etc. without even touching your descriptor.
It's also safer, as the credentials are not written in the plain file left on your server.
As a side note, please remember that the javax.persistence.jdbc.* properties are a JPA provider must requirement for the Java SE environment, but it's optional for Java EE.
Hope that helps!
Do I have to place mysql connector into
JBOSS_HOME/standalone/deployments directory to use MySQL in my
application?
Yes you need to put Mysql J/connector for use it as JDBC Driver. Your application server (JBOss, Weblogic, Glassfish, etc) doesn't provide it because depend of the RDBMS that you are using (in this case Mysql) and the version of it.
In the case of JBoss 7 the JDBC driver can be installed into the container in one of two ways: either as a deployment or as a core module. For the pros/cons of both modes an detailed explanatio you can check the following documentation: http://community.jboss.org/wiki/DataSourceConfigurationInAS7