Я пытаюсь использовать Spring Social для подключения к Facebook.Это ошибка, которую я получаю:
Description:
Parameter 1 of constructor in Application.Facebook.FacebookController required a bean of type 'org.springframework.social.connect.ConnectionRepository' that could not be found.
Action:
Consider defining a bean of type 'org.springframework.social.connect.ConnectionRepository' in your configuration.
Это учебник, которому я следовал: https://stackabuse.com/how-to-access-the-facebook-api-with-java-and-spring-boot/
Он просто не работает, потому что он дает мне ошибку, упомянутую выше
Я попытался клонировать репо здесь: https://github.com/DavidLandup/HowToAccessFacebookAPIWithSpringBoot, и оно не работает
структура:
main
+- java
+- Application
+- Facebook
+- FacebookController.java
+- Application.java
FacebookController.java
@Controller
@RequestMapping("/")
public class FacebookController {
private Facebook facebook;
private ConnectionRepository connectionRepository;
public FacebookController(Facebook facebook, ConnectionRepository connectionRepository) {
this.facebook = facebook;
this.connectionRepository = connectionRepository;
}
@GetMapping
public String helloFacebook(Model model) {
if (connectionRepository.findPrimaryConnection(Facebook.class) == null) {
return "redirect:/connect/fb";
}
model.addAttribute("facebookProfile", facebook.userOperations().getUserProfile());
PagedList<Post> feed = facebook.feedOperations().getFeed();
model.addAttribute("feed", feed);
return "feed";
}
}
Application.java
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.1.6.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
bootJar {
baseName = 'gs-spring-boot'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile(
'org.springframework.social:spring-social-core:1.1.6.RELEASE',
'org.springframework.social:spring-social-facebook:2.0.3.RELEASE',
'org.springframework.social:spring-social-twitter:1.1.0.RELEASE',
'org.springframework.boot:spring-boot-starter-web',
'org.springframework.boot:spring-boot-starter-thymeleaf'
)
}
Полная ошибка msg:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.6.RELEASE)
2019-09-26 13:20:24.043 INFO 88576 --- [ main]
2019-09-26 13:20:24.047 INFO 88576 --- [ main] Application.Application : No active profile set, falling back to default profiles: default
2019-09-26 13:20:25.113 INFO 88576 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2019-09-26 13:20:25.149 INFO 88576 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-09-26 13:20:25.149 INFO 88576 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.21]
2019-09-26 13:20:25.286 INFO 88576 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-09-26 13:20:25.286 INFO 88576 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1194 ms
2019-09-26 13:20:25.384 WARN 88576 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'facebookController' defined in file [/Users/user/Social_Media_Integration/backend/out/production/classes/Application/Facebook/FacebookController.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.social.connect.ConnectionRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
2019-09-26 13:20:25.388 INFO 88576 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2019-09-26 13:20:25.401 INFO 88576 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-09-26 13:20:25.586 ERROR 88576 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 1 of constructor in Application.Facebook.FacebookController required a bean of type 'org.springframework.social.connect.ConnectionRepository' that could not be found.
Action:
Consider defining a bean of type 'org.springframework.social.connect.ConnectionRepository' in your configuration.