2015-04-06 96 views
0

我正在構建一個簡單的應用程序使用春天和休眠,我想連接它與Facebook使用春天social.I我沒有使用初始化我的應用程序xml files.I已閱讀關於春季社會從它的官方網站。但這根本不是我的工作。雖然我試圖使用代碼它給我的錯誤「PagedList無法解析爲一種類型」 異常PagedList無法解析到一個類型不能解析爲一個類型,而使用春社會

java.lang.NoClassDefFoundError: org/springframework/social/ApiBinding 
    at java.lang.ClassLoader.defineClass1(Native Method) 
    at java.lang.ClassLoader.defineClass(Unknown Source) 
    at java.security.SecureClassLoader.defineClass(Unknown Source) 
    at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2957) 
    at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1210) 
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1690) 
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571) 
    at java.lang.Class.getDeclaredConstructors0(Native Method) 
    at java.lang.Class.privateGetDeclaredConstructors(Unknown Source) 
    at java.lang.Class.getDeclaredConstructors(Unknown Source) 

我的控制器類是

package net.codejava.spring.controller; 

import java.util.List; 

import javax.inject.Inject; 
import javax.servlet.http.HttpServletRequest; 

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

import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.social.facebook.api.Facebook; 
import org.springframework.social.facebook.api.Post; 
import org.springframework.stereotype.Controller; 
import org.springframework.ui.Model; 
import org.springframework.web.bind.annotation.ModelAttribute; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 
import org.springframework.web.bind.annotation.RequestParam; 
import org.springframework.web.servlet.ModelAndView; 

/** 
* Handles requests for the application home page. 
*/ 
@Controller 
public class HomeController { 

    private Facebook facebook; 
    @Autowired 
    private UserDAO userDao; 

    @RequestMapping(value = "/", method = RequestMethod.GET) 
    public ModelAndView checkLogin() { 
     ModelAndView model = new ModelAndView("LoginForm"); 
     return model;  
    } 
    @RequestMapping(value = "/fb", method = RequestMethod.GET) 
    public ModelAndView fbLogin() { 
     ModelAndView model = new ModelAndView("facebook"); 
     return model;  
    } 
    @RequestMapping(value = "/submit", method = RequestMethod.POST) 
    public ModelAndView processCredential(@RequestParam("username")String username,@RequestParam("password")String password) { 
     String message = "Invalid credentials"; 
     if(!username.equals("")&&!password.equals("")) 
     { 
      if(username.equals(username)&&password.equals(password)){ 
       message = "Welcome" +username+"!!!!"; 
      } 
     } 
    return new ModelAndView("result","message",message); 
    } 
    @RequestMapping("/list") 
    public ModelAndView handleRequest() throws Exception { 
     List<User> listUsers = userDao.list(); 
     ModelAndView model = new ModelAndView("UserList"); 
     model.addObject("userList", listUsers); 
     return model; 
    } 

    @RequestMapping(value = "/new", method = RequestMethod.GET) 
    public ModelAndView newUser() { 
     ModelAndView model = new ModelAndView("UserForm"); 
     model.addObject("user", new User()); 
     return model;  
    } 

    @RequestMapping(value = "/edit", method = RequestMethod.GET) 
    public ModelAndView editUser(HttpServletRequest request) { 
     int userId = Integer.parseInt(request.getParameter("id")); 
     User user = userDao.get(userId); 
     ModelAndView model = new ModelAndView("UserForm"); 
     model.addObject("user", user); 
     return model;  
    } 

    @RequestMapping(value = "/delete", method = RequestMethod.GET) 
    public ModelAndView deleteUser(HttpServletRequest request) { 
     int userId = Integer.parseInt(request.getParameter("id")); 
     userDao.delete(userId); 
     return new ModelAndView("redirect:/");  
    } 

    @RequestMapping(value = "/save", method = RequestMethod.POST) 
    public ModelAndView saveUser(@ModelAttribute User user) { 
     userDao.saveOrUpdate(user); 
     return new ModelAndView("redirect:/"); 
    } 
    @Inject 
    public HomeController(Facebook facebook) { 
     this.facebook = facebook; 
    } 
     @RequestMapping(method=RequestMethod.GET) 
     public String helloFacebook(Model model) { 
      if (!facebook.isAuthorized()) { 
       return "redirect:/connect/facebook"; 
      } 

      model.addAttribute(facebook.userOperations().getUserProfile()); 
      PagedList<Post> homeFeed = facebook.feedOperations().getHomeFeed(); 
      model.addAttribute("feed", homeFeed); 

      return "hello"; 
     } 

} 

我ApplicationContectConfig類是在那裏我聲明的Facebook的屬性文件

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); 
    } 
} 

我已經推杆在src /主/資源我的Facebook屬性文件 請提供給我的解決方案

回答

0

您展示的異常也不說關於PagedList。但是,您提到的異常或您展示的異常都可以解釋爲類路徑問題。從你所說的和顯示的看來,你的運行時類路徑缺少Spring社區庫。但我無法解釋爲什麼,因爲我不知道你是如何構建或運行應用程序的。如果有我可以查看的GitHub回購,那可能很有用。否則,我只是猜測。

相關問題