Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Spring with Hibernate Integrating Hibernate with Spring Configure Spring for Hibernate

Aryan Azimzadeh
Aryan Azimzadeh
1,271 Points

Get an error about driver class name

I don't know why I get error when I run the code and I get null for driver class error.

com/teamtreehouse/contactmgr/config/DataConfig.java
package com.teamtreehouse.contactmgr.config;

import org.apache.tomcat.dbcp.dbcp2.BasicDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.orm.hibernate5.LocalSessionFactoryBean;

import javax.sql.DataSource;
@Configuration
@PropertySource("app.properties")
public class DataConfig {
  @Autowired
  private Environment env;
  @Bean
  public DataSource dataSource(){
   BasicDataSource ds = new BasicDataSource();

  ds.setDriverClassName(env.getProperty("org.h2.Driver"));

    ds.setUrl(env.getProperty("jdbc:h2:mem:contactmgr"));
  return ds;
  } 
}
app.properties
giflib.db.driver = org.h2.Driver
giflib.db.url = jdbc:h2:mem:contactmgr
Justas Semaska
Justas Semaska
6,512 Points

You are defining properties in the app.properties file but not using them :)

Replace "org.h2.Driver" and "jdbc:h2:mem:contactmgr" in the getProperty() methods with the names from app.properties file. giflib.db.driver and giflib.db.url respectively.