Problem with Spring @Configuration class

Posted by easyrider on Stack Overflow See other posts from Stack Overflow or by easyrider
Published on 2010-05-16T07:30:07Z Indexed on 2010/05/16 7:40 UTC
Read the original article Hit count: 427

Filed under:
|
|

Hi, i use class with @Configuration annotation to configure my spring application:


@Configuration
public class SpringConfiguration {

 @Value("${driver}")
 String driver;

 @Value("${url}")
 String url;

 @Value("${minIdle}")
 private int minIdle;
       // snipp ..  

 @Bean(destroyMethod = "close")
 public DataSource dataSource() {
  DataSource dataSource = new DataSource();
  dataSource.setDriverClassName(driver);
  dataSource.setUrl(url);
  dataSource.setUsername(user);
  dataSource.setPassword(password);
  dataSource.setMinIdle(minIdle);

  return dataSource;
 }



and properties file in CLASSPATH

driver=org.postgresql.Driver
url=jdbc:postgresql:servicerepodb
minIdle=1

I would like to get my DataSource configured object in my DAO class:

ApplicationContext ctx = new AnnotationConfigApplicationContext(SpringConfiguration.class);   
DataSource dataSource = ctx.getBean(DataSource.class);

But i get the error:


org.springframework.beans.factory.BeanCreationException:
 Error creating bean with name 'springConfiguration': Injection of autowired dependencies 
failed; nested exception is org.springframework.beans.factory.BeanCreationException: 
Could not autowire field: private int de.hska.repo.configuration.SpringConfiguration.minIdle; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'int'; nested exception is **java.lang.NumberFormatException: For input string: "${minIdle}"**

Caused by: java.lang.NumberFormatException: For input string: **"${minIdle}"**
 at java.lang.NumberFormatException.forInputString(**Unknown Source**)
 at java.lang.Integer.parseInt(Unknown Source)
 at java.lang.Integer.valueOf(Unknown Source)

It worked with String properties (driver, url), but ${minIdle} (of type int) can't be resolved! Please help. Thanx in advance!

© Stack Overflow or respective owner

Related posts about spring

Related posts about configuration