mardi 7 avril 2015

How to load Facebook property file in java using Spring and Hibernate

I am new to spring and hibernate.I was trying to connect my web application with Facebook.I have done this using the java script provided by Facebook but I want to connect Facebook using Spring Social. For this purpose I have to declare a properties file under scr/main/resource folder.I have done this but I am not using any xml file. I have a class which loads all the properties and Dao files.I don't know the method of loading the properties file of Facebook.


My Applicationconfig class is



package net.codejava.spring.config;

import java.util.Properties;

import javax.sql.DataSource;

import net.codejava.spring.dao.UserDAO;
import net.codejava.spring.dao.UserDAOImpl;
import net.codejava.spring.model.User;

import org.apache.commons.dbcp2.BasicDataSource;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.orm.hibernate4.HibernateTransactionManager;
import org.springframework.orm.hibernate4.LocalSessionFactoryBuilder;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

@Configuration
@ComponentScan("net.codejava.spring")
@EnableTransactionManagement
public class ApplicationContextConfig {
@Bean(name = "viewResolver")
public InternalResourceViewResolver getViewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setPrefix("/WEB-INF/views/");
viewResolver.setSuffix(".jsp");
return viewResolver;
}


@Bean(name = "dataSource")
public DataSource getDataSource() {
BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
dataSource.setUrl("jdbc:mysql://localhost:3306/testing");
dataSource.setUsername("root");
dataSource.setPassword("4261");

return dataSource;
}


private Properties getHibernateProperties() {
Properties properties = new Properties();
properties.put("hibernate.show_sql", "true");
properties.put("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
return properties;
}
/*private Properties getFacebookProperties(){
Properties properties = new Properties();
properties.put("spring.social.facebook.appId", "809280815833386");
properties.put("spring.social.facebook.appSecret","24035c462c9d1fca367ff813436b15d8");

return properties;
}*/

@Autowired
@Bean(name = "sessionFactory")
public SessionFactory getSessionFactory(DataSource dataSource) {
LocalSessionFactoryBuilder sessionBuilder = new LocalSessionFactoryBuilder(dataSource);
sessionBuilder.addProperties(getHibernateProperties());
sessionBuilder.addAnnotatedClasses(User.class);
return sessionBuilder.buildSessionFactory();
}

@Autowired
@Bean(name = "transactionManager")
public HibernateTransactionManager getTransactionManager(
SessionFactory sessionFactory) {
HibernateTransactionManager transactionManager = new HibernateTransactionManager(
sessionFactory);

return transactionManager;
}

@Autowired
@Bean(name = "userDao")
public UserDAO getUserDao(SessionFactory sessionFactory) {
return new UserDAOImpl(sessionFactory);
}
}


My application.properties file is



spring.social.facebook.appId=appId
spring.social.facebook.appSecret=appSecret


Please provide the solution


Aucun commentaire:

Enregistrer un commentaire