File tree Expand file tree Collapse file tree 2 files changed +10
-3
lines changed Expand file tree Collapse file tree 2 files changed +10
-3
lines changed Original file line number Diff line number Diff line change 2
2
3
3
import org .springframework .data .annotation .Id ;
4
4
import org .springframework .data .mongodb .core .geo .GeoJsonPoint ;
5
- import org .springframework .data .mongodb .core .index .GeoSpatialIndexType ;
6
- import org .springframework .data .mongodb .core .index .GeoSpatialIndexed ;
7
5
8
6
/**
9
7
* A named location, using GeoJSON API.
@@ -13,7 +11,6 @@ public class Location {
13
11
14
12
@ Id private String id ;
15
13
16
- @ GeoSpatialIndexed (type = GeoSpatialIndexType .GEO_2DSPHERE )
17
14
private GeoJsonPoint position ;
18
15
19
16
public Location () {}
Original file line number Diff line number Diff line change 16
16
import org .springframework .data .geo .Distance ;
17
17
import org .springframework .data .geo .Metrics ;
18
18
import org .springframework .data .geo .Point ;
19
+ import org .springframework .data .mongodb .core .MongoTemplate ;
20
+ import org .springframework .data .mongodb .core .index .GeoSpatialIndexType ;
21
+ import org .springframework .data .mongodb .core .index .GeospatialIndex ;
19
22
import org .springframework .test .context .ContextConfiguration ;
20
23
import org .springframework .test .context .junit4 .SpringJUnit4ClassRunner ;
21
24
@@ -33,10 +36,17 @@ public class LocationRepositoryTest {
33
36
34
37
private static final Point DUS = new Point ( 6.810036 , 51.224088 );
35
38
39
+ @ Autowired
40
+ private MongoTemplate template ;
41
+
36
42
@ Autowired
37
43
LocationRepository repo ;
38
44
39
45
@ Before public void setUp () {
46
+ template
47
+ .indexOps (Location .class )
48
+ .ensureIndex (new GeospatialIndex ("position" ).typed (GeoSpatialIndexType .GEO_2DSPHERE ));
49
+
40
50
// prepare data
41
51
repo .save ( new Location ("A" , 0.001 , -0.002 ) );
42
52
repo .save ( new Location ("B" , 1 , 1 ) );
You can’t perform that action at this time.
0 commit comments