IntelliJ运行vs运行jar,带有Social Oauth2的Springboot Kotlin,Multi模块Gradle项目

TL; DR :为什么在通过IntelliJ启动时一切正常,为什么在调用java -jar app.jar时会java -jar app.jar 。 我该如何解决这个问题?


好吧,我有一些后端问题,我试图dockerize。 我有一个使用Spring Boot(1.4.2.RELEASE) 在其页面上的Spring Oauth(2.0.12.RELEASE) 指南之后创建的应用程序。 我遵循Gradle版本,因为我比Graven更喜欢Gradle。 此外,我正在使用Kotlin而不是Java。 一切都很好,我开始通过IntelliJ我的后端静态前端,我可以通过Facebook(和谷歌和Github)登录,我收到一个很好的Principal女巫掌握我需要的信息,我可以修改Spring安全授权和允许端点。 到现在为止还挺好。

现在对于不好的部分,当我运行./gradlew clean build app:bootrun./gradlew clean build app:jar并通过java -jar运行jar(就像我将在我的Docker容器中),我的后端出现。 我的静态前端弹出。 现在我想通过Facebook登录,我最终在Facebook登录页面,我输入我的凭据,… 什么都没有
我终于回到我的主页,没有登录,没有任何对我意味着什么的日志消息,只是沉默。 我在日志中看到的最后一件事是:
Getting user info from: https://graph.facebook.com/me

这个Url会在我的浏览器中给我:

 { "error": { "message": "An active access token must be used to query information about the current user.", "type": "OAuthException", "code": 2500, "fbtrace_id": "GV/58H5f4fJ" } } 

当通过IntelliJ开始到这个URL,它会给我的凭据细节。 显然有什么问题,但我不知道是什么。 特别是从IntelliJ运行良好。 这个jar是如何启动的,以及IntelliJ的运行配置是如何工作的,但是我不知道在哪里搜索什么。 我可以发布跟踪日志记录,或所有我的Gradle文件,但也许这太多的信息放在1个问题。 我会defenitly更新这个问题,如果有人需要一些更多的细节:)

这个项目的结构大纲如下:

 root: - api: is going to be opensourced later, contains rest definitions and DTOs. - core: contains the meat. Also here is included in the gradle file spring-boot-starter, -web, -security, spring-security-oauth2, and some jackson stuff. - rest: contains versioned rest service implementations. - app: contains angular webjars amongst others, the front end, and my `@SpringBootApplication`, `@EnableOAuth2Client` and the impl of `WebSecurityConfigurerAdapter`. 

为什么一切通过IntelliJ启动时运行良好,为什么使用bootRun或jar制品破坏。 我该如何解决这个问题?

我发现,问题不是Multi模块Graldle,Spring引导或者Oauth2相关。 实际上,这是由于Gradle的src设置配置,Java应该位于Java src设置文件夹中,而Kotlin位于Java src设置文件夹中:

 sourceSets { main.java.srcDirs += 'src/main/java' main.kotlin.srcDirs += 'src/main/kotlin' } 

正如Humphreys在上面的评论中所述,IntelliJ采用了所有的源代码集,并运行该应用程序。 但是,通过Gradle构建jar时,这些源代码集更加严格。 我在我的Kotlin src集合中有一个Java文件,这对于IntelliJ来说没有问题。 但是由Gradle创建的jar考虑到build.gralde文件中定义的源代码集,这些代码更严格。

我发现我的遗失的豆问题与下面的代码:

 @Bean public CommandLineRunner commandLineRunner(ApplicationContext ctx) { return args -> { System.out.println("Let's inspect the beans provided by Spring Boot:"); String[] beanNames = ctx.getBeanDefinitionNames(); Arrays.sort(beanNames); for (String beanName : beanNames) { System.out.println(beanName); } }; } 

我错过的Bean被称为AuthenticationController ,它是一个@RestController ,并且对于我的验证代码来说至关重要。