Spring MongoDB IntelliJ:如何从我的war项目配置定制jar项目
我与IntelliJ、Spring、Maven、Tomcat7和MongoDB合作 我有两个项目:Spring MongoDB IntelliJ:如何从我的war项目配置定制jar项目,spring,mongodb,maven,intellij-idea,tomcat7,Spring,Mongodb,Maven,Intellij Idea,Tomcat7,我与IntelliJ、Spring、Maven、Tomcat7和MongoDB合作 我有两个项目: JAR:这应该是一个身份验证服务 WAR:这将我的身份验证服务作为一个依赖项 现在,我的war项目中有以下bean配置: <!-- Factory bean that creates the Mongo instance --> <bean id="mongo" class="org.springframework.data.mongodb.core.Mong
- JAR:这应该是一个身份验证服务
- WAR:这将我的身份验证服务作为一个依赖项
<!-- Factory bean that creates the Mongo instance -->
<bean id="mongo" class="org.springframework.data.mongodb.core.MongoFactoryBean">
<property name="host" value="localhost" />
</bean>
<!-- MongoTemplate for connecting and quering the documents in the database -->
<bean id="jwt" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg name="mongo" ref="mongo" />
<constructor-arg name="databaseName" value="ProjectDB" />
</bean>
<!-- Use this post processor to translate any MongoExceptions
thrown in @Repository annotated classes -->
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
<!-- ########################################################################### -->
<!-- Configuration for auth -->
<!-- ########################################################################### -->
<!-- MongoTemplate for connecting and quering the documents in the database -->
<bean id="auth" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg name="mongo" ref="mongo" />
<constructor-arg name="databaseName" value="ProjectDB-auth" />
</bean>
我需要删除此文件,但IntelliJ无法解析对@Autowired private MongoTemplate auth的依赖关系代码>
我认为我的配置一切都有问题,尽管它工作正常。但是如何以正确的方式配置我的两个项目呢?我认为您的设置一切都很好
您希望创建一个供任何客户机使用的JAR,在本例中是WAR。您对数据库有依赖关系。通过省略JAR中的任何Spring配置,可以不声明此依赖关系。这是不干净的。此外,IDE会抱怨,因为它无法检查项目的有效性
最好声明该依赖关系,这与C或Maven依赖关系中的头文件非常相似,提供了作用域
。如您所做的那样,将Spring配置添加到项目中。告诉您库的用户将该配置包含到他们自己的配置中,或者将该配置用作文档,以查看您的工件只需要存在哪些bean就可以工作。您所说的“一切都错了”是什么意思?也许是“没什么不对劲”吧?对不起,我失败了,我的意思是我的配置出了问题:P
<!-- Factory bean that creates the Mongo instance -->
<bean id="mongo" class="org.springframework.data.mongodb.core.MongoFactoryBean">
<property name="host" value="localhost" />
</bean>
<!-- MongoTemplate for connecting and quering the documents in the database -->
<bean id="test" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg name="mongo" ref="mongo" />
<constructor-arg name="databaseName" value="AuthDBBase-notInUse" />
</bean>
<!-- Use this post processor to translate any MongoExceptions
thrown in @Repository annotated classes -->
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />