Announcement Announcement Module
Collapse
No announcement yet.
<bean class=${some.class.name.as.a.variable} Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • <bean class=${some.class.name.as.a.variable}

    hi, I have a config like that

    HTML Code:
    <bean id="propertyPlaceholder"
      class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
      <property name="locations">
       <list>
        <value>classpath:bla.properties</value>
       </list>
      </property>
     </bean>
     
    
    <bean id="dataSource" class="${spring.datasource.class}">
      <property name="driverClassName" value="${datasource.driver}" />
      <property name="url" value="${datasource.url}" />
      <property name="username" value="${datasource.username}" />
      <property name="password" value="${datasource.password}" />
     </bean>
    and I get this stack trace wich appear only in debug and not in info loglevel

    15:25:04,824 DEBUG org.springframework.context.annotation.Configurati onClassBeanDefinitionReader - Could not find class file for introspecting factory methods: ${spring.datasource.class}
    java.io.FileNotFoundException: class path resource [${spring/datasource/class}.class] cannot be opened because it does not exist
    so in fact it works, because spring does a second pass, however I was wondering if there was some better way to have a classname as a avariable avoiding a stacktrace

    here I use a log4jdbc wrapper on the spring datasource class

  • #2
    I found an ugly solution, but at least there is not stacktrace anymore
    I hope someone can come with something better

    HTML Code:
    	<bean id="dataSource" class="CustomisableDataSource">
    		<constructor-arg type="String" name="dataSourceClassName" value="${spring.datasource.class}"/>
    		<property name="driverClassName" value="${datasource.driver}" />
    		<property name="url" value="${datasource.url}" />
    		<property name="username" value="${datasource.username}" />
    		<property name="password" value="${datasource.password}" />
    	</bean>
    Code:
    public class CustomisableDataSource implements DataSource {
    
    	DriverManagerDataSource datasource;
    
    	public CustomisableDataSource(String dataSourceClassName) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
    		this.datasource = (DriverManagerDataSource) Class.forName(dataSourceClassName).newInstance();
    	}
    .
    .
    .
    }

    Comment

    Working...
    X