Play-Framework 2.4 未选择 Spring-Data-Mongodb 依赖项 [英] Spring-Data-Mongodb depedencies not picked by Play-Framework 2.4

查看:26
本文介绍了Play-Framework 2.4 未选择 Spring-Data-Mongodb 依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Spring-Data-Mongodb 中使用 play-framework 2.4.但是当我编译项目时,编译会抛出一个错误:

I am using play-framework 2.4 with Spring-Data-Mongodb. But when i compile the project the compile throw an error:

[error] /home/james/play-spring-data-mongodb/app/configuration/SpringDataMongoConfiguration.java:10: package org.springframework.data.mongodb.config does not exist
[error] org.springframework.data.mongodb.config.AbstractMongoConfiguration
[error] /home/james/play-spring-data-mongodb/app/configuration/SpringDataMongoConfiguration.java:11: package org.springframework.data.mongodb.repository.config does not exist
[error] org.springframework.data.mongodb.repository.config.EnableMongoRepositories
[error] /home/james/play-spring-data-mongodb/app/configuration/SpringDataMongoConfiguration.java:25: cannot find symbol
[error]   symbol: class AbstractMongoConfiguration
[error] AbstractMongoConfiguration
[error] /home/james/play-spring-data-mongodb/app/configuration/SpringDataMongoConfiguration.java:24: cannot find symbol
[error]   symbol: class EnableMongoRepositories
[error] EnableMongoRepositories

最重要的是,昨天这工作得很好.但是今天我在尝试编译项目时遇到了这个错误.我的 build.sbt 文件如下:

The main thing is that, yesterday this works perfectly. But today i got this error, when trying to compile the project. My build.sbt file as below:

name := """play-mongo-template"""

version := "1.0-SNAPSHOT"

lazy val root = (project in file(".")).enablePlugins(PlayJava)

scalaVersion := "2.11.6"

libraryDependencies ++= Seq(
    javaJdbc,
    cache,
    javaWs,
    "org.springframework" % "spring-context" % "4.1.6.RELEASE",
    "org.springframework.data" % "spring-data-mongodb-parent" % "1.7.2.RELEASE"
)

// Play provides two styles of routers, one expects its actions to be injected, the
// other, legacy style, accesses its actions statically.
routesGenerator := InjectedRoutesGenerator

更新

我发现了问题,问题在于,我们的play-framework激活器无法下载spring-framework依赖.当我打开 .ivy 文件夹并且没有可用的 jars 时.我的系统已连接互联网,但仍然播放 sbt 无法解析依赖项.我该如何解决这个问题?

I found the problem, THe problem is that, our play-framework activator unable to download spring-framework dependency. When i open the .ivy folder and there is no jars are available. My system is connected with Internet, but still play sbt not resolve dependencies. How could i resolve this problem?

推荐答案

要使用 Spring Data 中的存储库功能,生命周期必须由 Spring 管理.

To use the repository feature in Spring Data, the life cycle has to be managed by Spring.

因此在 Play 2.4/2.5 中使用它,而不添加 Spring 作为依赖项是一个问题,因为默认生命周期由 Guice 管理.

Hence using it with Play 2.4 / 2.5, without adding Spring as a dependency is a problem because the default life cycle is managed by Guice.

我想出了一种创建 Spring bean 并将其生命周期管理转移到 Guice 的方法.因此它们可以被 Guice 而不是 Spring 注入到项目中的任何地方.

I figured out a way to create the Spring beans and transfer its life cycle management to Guice. Hence they can be injected anywhere in the project by Guice instead of Spring.

对于其他没有Spring特有特性的组件,可以正常创建,生命周期由Guice管理.

For other components that don't have any Spring specific feature, they can be created normally and their life cycle will be managed by Guice.

对于 Spring 特有的只能在 Spring 容器内运行的其他组件,它们也可以注入到项目中,它们的生命周期将由 Guice 管理.

For other components, which are Spring specific and can only run inside a Spring container, they can also be injected in the project and their life cycle will managed by Guice.

我修改了 Play 2.5 文档中包含的入门项目来演示它.

I modified the starter project included in Play 2.5 docs to demonstrate it.

请查看此存储库.
https://github.com/mohitsinha/play-java-spring-data-mongodb

这篇关于Play-Framework 2.4 未选择 Spring-Data-Mongodb 依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆