Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
武汉红喜
whatsmars
提交
dcb0ae46
W
whatsmars
项目概览
武汉红喜
/
whatsmars
通知
3
Star
0
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
whatsmars
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
dcb0ae46
编写于
12月 04, 2019
作者:
武汉红喜
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
spring-data-mongodb
上级
8a38bb42
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
88 addition
and
4 deletion
+88
-4
whatsmars-spring-data/pom.xml
whatsmars-spring-data/pom.xml
+4
-0
whatsmars-spring-data/src/main/java/org/hongxi/whatsmars/spring/data/Application.java
...in/java/org/hongxi/whatsmars/spring/data/Application.java
+0
-2
whatsmars-spring-data/src/main/java/org/hongxi/whatsmars/spring/data/config/ElasticsearchConfiguration.java
...tsmars/spring/data/config/ElasticsearchConfiguration.java
+1
-1
whatsmars-spring-data/src/main/java/org/hongxi/whatsmars/spring/data/config/MogoConfiguration.java
...ongxi/whatsmars/spring/data/config/MogoConfiguration.java
+9
-0
whatsmars-spring-data/src/main/java/org/hongxi/whatsmars/spring/data/model/Customer.java
...java/org/hongxi/whatsmars/spring/data/model/Customer.java
+27
-0
whatsmars-spring-data/src/main/java/org/hongxi/whatsmars/spring/data/repository/CustomerRepository.java
.../whatsmars/spring/data/repository/CustomerRepository.java
+14
-0
whatsmars-spring-data/src/main/java/org/hongxi/whatsmars/spring/data/service/DataService.java
...org/hongxi/whatsmars/spring/data/service/DataService.java
+6
-0
whatsmars-spring-data/src/main/resources/application-test.properties
...pring-data/src/main/resources/application-test.properties
+5
-1
whatsmars-spring-data/src/main/resources/spring-mongo.xml
whatsmars-spring-data/src/main/resources/spring-mongo.xml
+22
-0
未找到文件。
whatsmars-spring-data/pom.xml
浏览文件 @
dcb0ae46
...
...
@@ -20,6 +20,10 @@
<groupId>
org.springframework.data
</groupId>
<artifactId>
spring-data-elasticsearch
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.data
</groupId>
<artifactId>
spring-data-mongodb
</artifactId>
</dependency>
<dependency>
<groupId>
org.hongxi
</groupId>
...
...
whatsmars-spring-data/src/main/java/org/hongxi/whatsmars/spring/data/Application.java
浏览文件 @
dcb0ae46
package
org.hongxi.whatsmars.spring.data
;
import
org.hongxi.whatsmars.common.profile.ProfileUtils
;
import
org.hongxi.whatsmars.spring.data.config.PropertyConfiguration
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
public
class
Application
{
public
static
void
main
(
String
[]
args
)
{
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
();
context
.
register
(
PropertyConfiguration
.
class
);
context
.
scan
(
"org.hongxi.whatsmars.spring.data"
);
context
.
getEnvironment
().
setActiveProfiles
(
ProfileUtils
.
getProfile
());
context
.
refresh
();
...
...
whatsmars-spring-data/src/main/java/org/hongxi/whatsmars/spring/data/config/E
s
Configuration.java
→
whatsmars-spring-data/src/main/java/org/hongxi/whatsmars/spring/data/config/E
lasticsearch
Configuration.java
浏览文件 @
dcb0ae46
...
...
@@ -9,7 +9,7 @@ import org.springframework.data.elasticsearch.client.TransportClientFactoryBean;
import
java.util.Properties
;
@Configuration
public
class
E
s
Configuration
{
public
class
E
lasticsearch
Configuration
{
@Value
(
"${es.cluster.name}"
)
private
String
clusterName
;
...
...
whatsmars-spring-data/src/main/java/org/hongxi/whatsmars/spring/data/config/MogoConfiguration.java
0 → 100644
浏览文件 @
dcb0ae46
package
org.hongxi.whatsmars.spring.data.config
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.ImportResource
;
@Configuration
@ImportResource
(
"classpath:spring-mongo.xml"
)
public
class
MogoConfiguration
{
}
whatsmars-spring-data/src/main/java/org/hongxi/whatsmars/spring/data/model/Customer.java
0 → 100644
浏览文件 @
dcb0ae46
package
org.hongxi.whatsmars.spring.data.model
;
import
org.springframework.data.annotation.Id
;
public
class
Customer
{
@Id
private
String
id
;
private
String
firstName
;
private
String
lastName
;
public
Customer
()
{
}
public
Customer
(
String
firstName
,
String
lastName
)
{
this
.
firstName
=
firstName
;
this
.
lastName
=
lastName
;
}
@Override
public
String
toString
()
{
return
String
.
format
(
"Customer[id=%s, firstName='%s', lastName='%s']"
,
id
,
firstName
,
lastName
);
}
}
\ No newline at end of file
whatsmars-spring-data/src/main/java/org/hongxi/whatsmars/spring/data/repository/CustomerRepository.java
0 → 100644
浏览文件 @
dcb0ae46
package
org.hongxi.whatsmars.spring.data.repository
;
import
org.hongxi.whatsmars.spring.data.model.Customer
;
import
org.springframework.data.mongodb.repository.MongoRepository
;
import
java.util.List
;
public
interface
CustomerRepository
extends
MongoRepository
<
Customer
,
String
>
{
Customer
findByFirstName
(
String
firstName
);
List
<
Customer
>
findByLastName
(
String
lastName
);
}
\ No newline at end of file
whatsmars-spring-data/src/main/java/org/hongxi/whatsmars/spring/data/service/DataService.java
浏览文件 @
dcb0ae46
package
org.hongxi.whatsmars.spring.data.service
;
import
org.elasticsearch.client.transport.TransportClient
;
import
org.hongxi.whatsmars.spring.data.repository.CustomerRepository
;
import
org.springframework.data.mongodb.core.MongoTemplate
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.stereotype.Service
;
...
...
@@ -13,4 +15,8 @@ public class DataService {
private
RedisTemplate
<
Integer
,
String
>
redisTemplate
;
@Resource
private
TransportClient
transportClient
;
@Resource
private
MongoTemplate
mongoTemplate
;
@Resource
private
CustomerRepository
customerRepository
;
}
whatsmars-spring-data/src/main/resources/application-test.properties
浏览文件 @
dcb0ae46
...
...
@@ -2,4 +2,8 @@ redis.host=127.0.0.1
redis.port
=
6379
es.cluster.name
=
elasticsearch
es.cluster.nodes
=
127.0.0.1:9300
\ No newline at end of file
es.cluster.nodes
=
127.0.0.1:9300
mongo.host
=
127.0.0.1
mongo.port
=
27017
mongo.db
=
test
\ No newline at end of file
whatsmars-spring-data/src/main/resources/spring-mongo.xml
0 → 100644
浏览文件 @
dcb0ae46
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns=
"http://www.springframework.org/schema/beans"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns:mongo=
"http://www.springframework.org/schema/data/mongo"
xsi:schemaLocation=
"http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/data/mongo
http://www.springframework.org/schema/data/mongo/spring-mongo.xsd"
>
<mongo:mongo-client
id=
"mongoClient"
host=
"${mongo.host}"
port=
"${mongo.port}"
>
<mongo:client-options
/>
</mongo:mongo-client>
<mongo:db-factory
dbname=
"${mongo.db}"
mongo-ref=
"mongoClient"
/>
<bean
id=
"mongoTemplate"
class=
"org.springframework.data.mongodb.core.MongoTemplate"
>
<constructor-arg
name=
"mongoDbFactory"
ref=
"mongoDbFactory"
/>
</bean>
<mongo:repositories
base-package=
"org.hongxi.whatsmars.spring.data.repository"
/>
</beans>
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录