2

Getting like thoudsands of these line, when running my jar from java -jar foo.jar, so the application takes atleast 1 minute to boot up.

2012-10-04 09:31:56,543 [AWT-EventQueue-0] DEBUG org.hibernate.ejb.packaging.AbstractJarVisitor - Filtering: org.springframework.context.annotation.DependsOn
2012-10-04 09:31:56,546 [AWT-EventQueue-0] DEBUG org.hibernate.ejb.packaging.AbstractJarVisitor - Filtering: org.springframework.context.annotation.EnableAspectJAutoProxy
2012-10-04 09:31:56,548 [AWT-EventQueue-0] DEBUG org.hibernate.ejb.packaging.AbstractJarVisitor - Filtering: org.springframework.context.annotation.EnableLoadTimeWeaving$AspectJWeaving
2012-10-04 09:31:56,553 [AWT-EventQueue-0] DEBUG org.hibernate.ejb.packaging.AbstractJarVisitor - Filtering: org.springframework.context.annotation.EnableLoadTimeWeaving
2012-10-04 09:31:56,558 [AWT-EventQueue-0] DEBUG org.hibernate.ejb.packaging.AbstractJarVisitor - Filtering: org.springframework.context.annotation.FilterType
2012-10-04 09:31:56,561 [AWT-EventQueue-0] DEBUG org.hibernate.ejb.packaging.AbstractJarVisitor - Filtering: org.springframework.context.annotation.Import
2012-10-04 09:31:56,563 [AWT-EventQueue-0] DEBUG org.hibernate.ejb.packaging.AbstractJarVisitor - Filtering: org.springframework.context.annotation.ImportAware
2012-10-04 09:31:56,567 [AWT-EventQueue-0] DEBUG org.hibernate.ejb.packaging.AbstractJarVisitor - Filtering: org.springframework.context.annotation.ImportBeanDefinitionRegistrar
2012-10-04 09:31:56,571 [AWT-EventQueue-0] DEBUG org.hibernate.ejb.packaging.AbstractJarVisitor - Filtering: org.springframework.context.annotation.ImportResource
2012-10-04 09:31:56,575 [AWT-EventQueue-0] DEBUG org.hibernate.ejb.packaging.AbstractJarVisitor - Filtering: org.springframework.context.annotation.ImportSelector
2012-10-04 09:31:56,578 [AWT-EventQueue-0] DEBUG org.hibernate.ejb.packaging.AbstractJarVisitor - Filtering: org.springframework.context.annotation.Jsr330ScopeMetadataResolver
2012-10-04 09:31:56,581 [AWT-EventQueue-0] DEBUG org.hibernate.ejb.packaging.AbstractJarVisitor - Filtering: org.springframework.context.annotation.Lazy
2012-10-04 09:31:56,585 [AWT-EventQueue-0] DEBUG org.hibernate.ejb.packaging.AbstractJarVisitor - Filtering: org.springframework.context.annotation.LoadTimeWeavingConfiguration
2012-10-04 09:31:56,589 [AWT-EventQueue-0] DEBUG org.hibernate.ejb.packaging.AbstractJarVisitor - Filtering: org.springframework.context.annotation.LoadTimeWeavingConfigurer
2012-10-04 09:31:56,593 [AWT-EventQueue-0] DEBUG org.hibernate.ejb.packaging.AbstractJarVisitor - Filtering: org.springframework.context.annotation.MetadataUtils
2012-10-04 09:31:56,596 [AWT-EventQueue-0] DEBUG org.hibernate.ejb.packaging.AbstractJarVisitor - Filtering: org.springframework.context.annotation.Primary

I am creating my JAR with Maven Shade:

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.0</version>

The Spring and Hibernate configuration:

<bean id="entityManagerFactory" 
      class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
  <property name="dataSource" ref="dataSource"/>
</bean>
<bean id="transactionManager"
      class="org.springframework.orm.jpa.JpaTransactionManager">
  <property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>

How can I filter it to not search all JARs that are downloaded by POM?

EDIT:

Full Spring configuration:

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.1.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">

<context:component-scan base-package="my.foo.bar" />

<context:property-placeholder location="classpath:/config/database.properties"/>

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="${database.driverClassName}"/>
    <property name="url" value="${database.url}"/>
    <property name="username" value="${database.username}"/>
    <property name="password" value="${database.password}"/>
</bean>

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource"/>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>

full persistence:

 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<persistence 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_1_0.xsd"
         version="1.0">
<persistence-unit name="persistenceUnit">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <properties>
        <property name="hibernate.dialect" value="dialect.ImprovedH2Dialect"/>
        <property name="hibernate.default_schema" value="ags" />
        <property name="hibernate.show_sql" value="true"/>
        <!-- value="create" to build a new database on each run; value="update" to modify an existing database; value="create-drop" means the same as "create" but also drops tables when Hibernate closes; value="validate" makes no changes to the database -->
        <property name="hibernate.hbm2ddl.auto" value="create"/>
        <property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy"/>
        <property name="hibernate.connection.charSet" value="UTF-8"/>
    </properties>
</persistence-unit>

Jaanus
  • 16,161
  • 49
  • 147
  • 202

2 Answers2

2

You need to tune some settings in persistence.xml, add:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<persistence 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_1_0.xsd"
         version="1.0">
<persistence-unit name="persistenceUnit">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <class>my.foo.bar</class>
    <exclude-unlisted-classes>true</exclude-unlisted-classes>
    <properties>
        <property name="hibernate.dialect" value="dialect.ImprovedH2Dialect"/>
        <property name="hibernate.default_schema" value="ags" />
        <property name="hibernate.show_sql" value="true"/>
        <!-- value="create" to build a new database on each run; value="update" to modify an existing database; value="create-drop" means the same as "create" but also drops tables when Hibernate closes; value="validate" makes no changes to the database -->
        <property name="hibernate.hbm2ddl.auto" value="create"/>
        <property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy"/>
        <property name="hibernate.connection.charSet" value="UTF-8"/>
    </properties>
</persistence-unit> 

and specify all entity classes.

see http://docs.jboss.org/hibernate/entitymanager/3.6/reference/en/html/configuration.html

  • I added this line to my `persistence.xml` and all my Entitys are annotated, still scans every JAR that are in my Shade JAR. – Jaanus Oct 04 '12 at 06:59
  • Can you edit your question and provide your full spring context and full `persistence.xml`? –  Oct 04 '12 at 10:59
  • I did it, but still writes thousands of those lines. Very weird. – Jaanus Oct 04 '12 at 14:42
0

Try to add to your persistence.xml

 <exclude-unlisted-classes>true</exclude-unlisted-classes>

 <class>my.foo.bar.Entity1</class>
 <class>my.foo.bar.Entity2</class>
...
 <class>my.foo.bar.EntityN</class>

and remove <class>my.foo.bar</class>

and, maybe <jar-file>jar_with_my_foo_bar_Entity.jar</jar-file> will help

user1516873
  • 5,060
  • 2
  • 37
  • 56
  • 1
    I have each entity like that already. And I have 1 mega JAR file created that includes my entities and other libraries. It is created with `Maven Shade` – Jaanus Oct 05 '12 at 10:42
  • So, try to set debug level to INFO, and change logging format to something without classname. But i think you cannot make it much faster than it already is. – user1516873 Oct 05 '12 at 11:02
  • yeah but that is more like a hack, doesnt solve the actual problem – Jaanus Oct 07 '12 at 18:15