Connect to mySQL via GlassFish connection pool
<p>I'm having this error while trying to connect to mySQL database:</p>

<p><code>No object bound to name java:comp/env/jdbc/mySql</code></p>

<p>This is my configuration class:</p>

<pre><code>@Configuration
@EnableTransactionManagement
@ComponentScan({ "org.onmyown.config" })
@PropertySource(value = { "classpath:application.properties" })
public class HibernateConfiguration {

@Autowired
private Environment environment;

@Bean
public LocalSessionFactoryBean sessionFactory() {
    LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
    sessionFactory.setDataSource(dataSource());
    sessionFactory.setPackagesToScan(new String[] { "org.onmyown" });
    sessionFactory.setHibernateProperties(hibernateProperties());
    return sessionFactory;
}

@Bean
public DataSource dataSource() {
    DataSource dataSource = null;
    try {
        Context initialContext = new InitialContext();
        Context environmentContext = (Context)initialContext.lookup("java:comp/env");
        dataSource = (DataSource) environmentContext.lookup("jdbc/mySql");
    } catch (NamingException e) {
        e.printStackTrace();
    }
    return dataSource;
}

private Properties hibernateProperties() {
    Properties properties = new Properties();
    properties.put("hibernate.dialect", environment.getRequiredProperty("hibernate.dialect"));
    properties.put("hibernate.show_sql", environment.getRequiredProperty("hibernate.show_sql"));
    properties.put("hibernate.format_sql", environment.getRequiredProperty("hibernate.format_sql"));
    properties.put("hibernate.hbm2ddl.auto", environment.getRequiredProperty("hibernate.hbm2ddl.auto"));
    return properties;
}

@Bean
@Autowired
public HibernateTransactionManager transactionManager(SessionFactory s) {
    HibernateTransactionManager txManager = new HibernateTransactionManager();
    txManager.setSessionFactory(s);
    return txManager;
}
}
</code></pre>

<p>I can ping from GlassFish just fine. I put all the properties I need (I think). My friend did this configuration with Derby database and it works. Is there any difference?</p>

<p>@edit</p>

<p>I 'fixed' something. I added web.xml, everything is here:</p>

<p><a href="https://github.com/afterlook/SpringMVC" rel="nofollow">https://github.com/afterlook/SpringMVC</a></p>

<p>The problem now is that the application doesn't really care that i put mySql as a data source. It searches for DerbyPool which is one of the defaults in GlassFish. Any idea why?</p>