Results 1 to 5 of 5

Thread: Scripting the container configuration file.

  1. #1
    Join Date
    Aug 2004
    Location
    Weston, FL, USA
    Posts
    23

    Default Scripting the container configuration file.

    Hello everyone,
    Are there any plans to add support for scripting languages for the configuration file of the Spring container? For example, use Jython instead of XML to write the configuration file.

    Thanks,
    Alex.

  2. #2
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    Yes there are...

    We're currently thinking about Groovy, Java an possibly also Jython... But this won't be done before at the earliest release 1.2 I guess

    alef
    Alef Arendsen
    SpringSource
    http://www.springsource.com

  3. #3
    Join Date
    Sep 2004
    Location
    Leuven, Belgium
    Posts
    1,853

    Default

    Java configuration would be using BeanShell I guess?

    Erwin

  4. #4
    Join Date
    Jan 2005
    Location
    Seattle, WA
    Posts
    2

    Default

    Alex,

    Inspired by this blog http://www.almaer.com/blog/archives/000356.html, I tried to implement a basic JythonBeanFactory in the last weekend. By reading the source code of Jython utility package, I finally make this BeanFactory work.

    Basically, the configuraiton(ApplicaitionContext.py) looks like this:
    Code:
    from JythonContextUtil import getBeansList
    beans_list = {}
    
    # Real Configuration. 
    from java import util
    d = util.Date()
    beans_list["d"] = d
    
    from org.apache.commons.dbcp import BasicDataSource 
    myDataSource = BasicDataSource(
    	driverClassName = "com.mysql.jdbc.Driver",
    	url="jdbc:mysql://localhost:3306/xplanner",
    	username="test",
    	password="test"
    )
    beans_list["datasource"] = myDataSource
    
    #	convert beans_list to java Map
    beanlist = getBeansList(beans_list)
    From Java side, we can use "getBean" method to get the real java instance.
    Code:
    BeanFactory factory = new JythonBeanFactory("ApplicaitionContext.py");
    Date d = (Date)factory.getBean("d");
    System.out.println(d);
            
    DataSource datasource = (DataSource) factory.getBean("datasource");
    The way I implement the BeanFactory is using a PyDictionary object to store PyObjects or Java instances created in Jython file, then convert it to Java Map object in the JythonBeanFactory. In the above "ApplicaitionContext.py" file, we actually get two beans, whose names are "d" and "datasource".

    cheers,

    Yan

  5. #5
    Join Date
    Aug 2004
    Location
    Weston, FL, USA
    Posts
    23

    Default

    Thank you very much Yan!! Your post is very helpful and I'm going to follow your approach.

    Best regards,
    Alex.

Similar Threads

  1. Saving large files to a db using hibernate?
    By Dan Washusen in forum Data
    Replies: 10
    Last Post: Sep 20th, 2006, 12:18 PM
  2. How to use Spring with custom configuration file
    By dmajumdar in forum Container
    Replies: 1
    Last Post: May 7th, 2006, 11:34 AM
  3. Can't find the configuration file in WebLogic...
    By anagnost68 in forum Container
    Replies: 1
    Last Post: Sep 8th, 2005, 01:00 AM
  4. Templating the Spring configuration file
    By meagle in forum Container
    Replies: 3
    Last Post: Mar 20th, 2005, 05:16 AM
  5. Replies: 5
    Last Post: Aug 27th, 2004, 07:13 PM

Posting Permissions

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