Spring-Data-Mongodb依赖项未被Play-Framework 2.4选中 [英] Spring-Data-Mongodb depedencies not picked by Play-Framework 2.4
问题描述
我正在使用Spring-Data-Mongodb的play-framework 2.4。但是当我编译项目时,编译抛出一个错误:
[error] / home / james / play-spring-data- mongodb / app / configuration / SpringDataMongoConfiguration.java:10:package org.springframework.data.mongodb.config不存在
[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不存在
[error] org.springframework.data .mongodb.repository.config.EnableMongoRepositories
[错误] /home/james/play-spring-data-mongodb/app/configuration/SpringDataMongoConfiguration.java:25:找不到符号
[错误]符号: class AbstractMongoConfiguration
[error] AbstractMongoConfiguration
[error] /home/james/play-spring-data-mongodb/app/configuration/SpringDataMongoConfiguration.java:24:找不到符号
[错误] symbol:class EnableMongoRepositories
[错误] EnableMongoRepositories
最重要的是,昨天这完美无缺。但是今天我在尝试编译项目时遇到了这个错误。我的 build.sbt
文件如下:
name:= play-mongo-template
版本:=1.0-SNAPSHOT
lazy val root =(项目文件(。))。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提供两种风格的路由器,一种期望注入其动作,
//其他遗留风格,静态访问其动作。
routesGenerator:= InjectedRoutesGenerator
更新
我发现了问题,问题是,我们的 play-framework
激活器无法下载spring-framework依赖项。当我打开.ivy文件夹时,没有可用的罐子。我的系统与Internet连接,但仍然没有解决依赖关系。我怎么能解决这个问题?
要在Spring Data中使用存储库功能,生命周期必须由Spring管理。
因此在Play 2.4 / 2.5中使用它,而不添加Spring作为依赖是一个问题,因为默认生命周期由Guice管理。
<我想出了一种创建Spring bean并将其生命周期管理转移到Guice的方法。因此,他们可以通过Guice而不是Spring注入项目的任何地方。
对于没有任何Spring特定功能的其他组件,可以正常创建它们,它们的生命周期将由Guice管理。
对于其他特定于Spring且只能在Spring容器中运行的组件,它们也可以在项目中注入,它们的生命周期将由Guice管理。
我修改了Play 2.5文档中包含的入门项目来演示它。
请查看此存储库。
https:// github。 com / mohitsinha / play-java-spring-data-mongodb
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
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
Update
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?
To use the repository feature in Spring Data, the life cycle has to be managed by Spring.
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.
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.
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.
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.
I modified the starter project included in Play 2.5 docs to demonstrate it.
Please have a look at this repository.
https://github.com/mohitsinha/play-java-spring-data-mongodb
这篇关于Spring-Data-Mongodb依赖项未被Play-Framework 2.4选中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!