Results 1 to 4 of 4

Thread: Multiple log4j configurations - Application & Test

  1. #1

    Default Multiple log4j configurations - Application & Test

    Hi all,
    I have application and test in the same project. Log4j.properties is under src/main/config. What I want is to load another log4j.properties only for testing purposes, for example placed into src/test/config and override the main one. Is it possible? How can I do this?
    Thanks in advance for help.

  2. #2

    Default

    one Possibility would be to use a different log4j configuration file and tell it log4j, just run the Tests with a special System Property

    @see http://logging.apache.org/log4j/1.2/manual.html (look for "Default Initialization Procedure" and the Example for Tomcat "Default Initialization under Tomcat")

  3. #3

    Default

    I need this behaviour also for other properties (hibernate.properties, etc...), because I want a complete different environment for testing. Can you give me some hints to organize my project better?

  4. #4

    Default

    that is no easy question nor task and depends heavily on your needs

    i can only give an example with a multi-module project

    - Persistance Project includes SessionFactory for Hibernate + a propertyPlaceHolderConfigurer - see Spring Core Doc, DOES NOT include the referenced dataSource
    - Test Project - includes the dataSource Definition for Test with placeHolders e.g. ${db.user} and ${hibernate.show_sql_comments}
    - the real project(s) uses Persistance Project AND Test Project, the last one with "test scope" meaning the TestProject.jar is only in the TestLibpath, it includes
    (under /src/test/...) a db.properties with those values for ${db.user} etc. the position is hard coded in the propertyPlaceholder e.g.classpath:resources/db.properties

    Consequences

    - the real Application needs a dataSource Definition for Production Mode, in my Case i use JNDI
    - one could use defaults within the propertyPlaceHolderConfigurer with test-Database-Data to make using the db.properties file optional
    - one can switch the database and hibernate properties (and more) within the db.properties file on the fly

    if you only have one Project you could create the DataSource and Sessionfactory programmatically with selfmade Utilclasses (and/or Spring Annotations)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •