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 Add JPA Annotations to Entities

vikas Rai
vikas Rai
9,703 Points

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactoryBean' defined in c

I am getting mentioned error when trying to launch my application.

1 Answer

J llama
J llama
12,631 Points

package com.teamtreehouse.giflib.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 LocalSessionFactoryBean sessionFactory() {
    Resource config = new ClassPathResource("hibernate.cfg.xml");
    LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
    sessionFactory.setConfigLocation(config);
    sessionFactory.setPackagesToScan(env.getProperty("giflib.entity.package"));
    sessionFactory.setDataSource(dataSource());
    return sessionFactory;
}

@Bean
public DataSource dataSource() {
    BasicDataSource ds = new BasicDataSource();

    // Driver class name
    ds.setDriverClassName(env.getProperty("giflib.db.driver"));

    // Set URL
    ds.setUrl(env.getProperty("giflib.db.url"));

    // Set username & password
    ds.setUsername(env.getProperty("giflib.db.username"));
    ds.setPassword(env.getProperty("giflib.db.password"));

    return ds;
}

}

giflib.hash.salt = xOBtdmJZxRcz^jkkyHfkrkT1*02bJUn+YQts0*xCeka%cGHCN1fjaC*faFtY

Package where our entities (models) are located

giflib.entity.package = com.teamtreehouse.giflib.model

Details for our datasource

giflib.db.driver = org.h2.Driver giflib.db.url = jdbc:h2:mem:giflib

giflib.db.url = jdbc:h2:tcp://localhost/~/Code/screencasts/giflib-hibernate/data/giflib

giflib.db.username = sa giflib.db.password =

here you go. the staff at this place suck the fact that ive spent 45 min of my life to figure this out and not a single one of their lazy team memebers could do this in the past few years is hilarious. cant wait to cancel