Bonjour,

Je cherche déséspérement depuis quelques jours une façon à intégrer une Arraylist dans un document Mongo.
Je vous explique :

Je veux arriver à stocker ce genre de document dans ma base mongo


Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
"_id" : "FRKASP78",
"os" : "Windows Server",
"version" : "2008",
"functions" : [
    "SFTP",
    "FTPS",
    "CFT",
    "AD"
],
"interventions" : {
    "title" : "Add User",
    "doneBy" : "Ahmed",
    "desc": "Some description here"
},
{
    "title" : "Something lese",
    "doneBy" : "test"
    "desc": "Some description here" 
}
}
J'ai donc créé ce modèle :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
@Document(collection = "equipements")
public class EquipementModel {
 
	@Id
	@NotNull
	@Size(min = 2, max = 10, message = "The name size must be between 2 and 10 characters")
	public String name;
 
	public String os;
 
	@NotNull
	@Size(min = 10, message = "The version size must be between 2 and 10 characters")
	public String version;
 
	@NotNull
	public ArrayList<String> functions;
 
	private List<InterventionsModel> interventions = new ArrayList<InterventionsModel>();
 
	@NotNull
	public String category;
 
	@NotNull
	public String privateIp;
 
	public String publicIp;
 
	@NotNull
	public String hardware;
 
	@NotNull
	public String hardwareType;
 
	@NotNull
	public String authMethod;
 
	public Date addedDate;
 
 
	public String getName() {
		return name;
	}
 
	public void setName(String name) {
		this.name = name;
	}
 
	public String getOs() {
		return os;
	}
 
	public void setOs(String os) {
		this.os = os;
	}
 
	public String getVersion() {
		return version;
	}
 
	public void setVersion(String version) {
		this.version = version;
	}
 
	public String getHardware() {
		return hardware;
	}
 
	public void setHardware(String hardware) {
		this.hardware = hardware;
	}
 
	public String getHardwareType() {
		return hardwareType;
	}
 
	public void setHardwareType(String hardwareType) {
		this.hardwareType = hardwareType;
	}
 
	public String getAuthMethod() {
		return authMethod;
	}
 
	public void setAuthMethod(String authMethod) {
		this.authMethod = authMethod;
	}
 
	public String getCategory() {
		return category;
	}
 
	public void setCategory(String category) {
		this.category = category;
	}
 
	public Date getAddedDate() {
		return addedDate;
	}
 
	public void setAddedDate(Date addedDate) {
		this.addedDate = addedDate;
	}
 
	public ArrayList<String> getFunctions() {
		return functions;
	}
 
	public void setFunctions(ArrayList<String> functions) {
		this.functions = functions;@Document(collection = "equipements")
public class EquipementModel {
 
@Id
@NotNull
@Size(min = 2, max = 10, message = "The name size must be between 2 and 10 characters")
public String name;
 
public String os;
 
@NotNull
@Size(min = 10, message = "The version size must be between 2 and 10 characters")
public String version;
 
@NotNull
public ArrayList<String> functions;
 
public ArrayList<InterventionsModel> interventions;
 
@NotNull
public String category;
 
@NotNull
public String privateIp;
 
public String publicIp;
 
@NotNull
public String hardware;
 
@NotNull
public String hardwareType;
 
@NotNull
public String authMethod;
 
public Date addedDate;
	}
 
	public List<InterventionsModel> getInterventions() {
		return interventions;
	}
 
	public void setInterventions(List<InterventionsModel> interventions) {
		this.interventions = interventions;
	}
 
	public String getPrivateIp() {
		return privateIp;
	}
 
	public void setPrivateIp(String privateIp) {
		this.privateIp = privateIp;
	}
 
	public String getPublicIp() {
		return publicIp;
	}
 
	public void setPublicIp(String publicIp) {
		this.publicIp = publicIp;
	}
 
 
 
}
Puis ce modèle :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
public class InterventionsModel {
 
	@NotNull
	@Size(min = 2, max = 10, message = "The name size must be between 2 and 10 characters")
	public String title;
 
	public String doneBy;
 
	public Date doneAt;
 
	public TextArea desc;
 
	public String getTitle() {
		return title;
	}
 
	public void setTitle(String title) {
		this.title = title;
	}
 
	public String getDoneBy() {
		return doneBy;
	}
 
	public void setDoneBy(String doneBy) {
		this.doneBy = doneBy;
	}
 
	public Date getDoneAt() {
		return doneAt;
	}
 
	public void setDoneAt(Date doneAt) {
		this.doneAt = doneAt;
	}
 
	public TextArea getDesc() {
		return desc;
	}
 
	public void setDesc(TextArea desc) {
		this.desc = desc;
	}
 
 
}

Ensuite j'ai créé ce service :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
@Repository
public class EquipementService {
 
	@Autowired
	private MongoTemplate mongoTemplate;
 
	public void addEquipement(EquipementModel equipement) {
		if (!mongoTemplate.collectionExists(EquipementModel.class)) {
			mongoTemplate.createCollection(EquipementModel.class);
		}
		mongoTemplate.insert(equipement);
	}
 
	public List<EquipementModel> listEquipement() {
		return mongoTemplate.findAll(EquipementModel.class);
	}
 
	public void deleteEquipement(EquipementModel equipement) {
		mongoTemplate.remove(equipement);
	}
 
	public void updateEquipment(EquipementModel equipement) {
		mongoTemplate.insert(equipement);
	}
 
 
}
Et enfin j'ai créé ce controleur :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
@Autowired
private EquipementService equipementService;
 
@RequestMapping(value = "/home", method = RequestMethod.GET)
public String getEquipementList(ModelMap model) {
    model.addAttribute("equipement", equipementService.listEquipement());
 
    return "home";
}
 
@RequestMapping(value = "/add", method = RequestMethod.GET)
public String addEquipement(ModelMap model) {
    model.addAttribute("getEquipementList", equipementService.listEquipement());
    model.addAttribute("equipement", new EquipementModel());
 
    return "newequipement";
}
 
@RequestMapping(value = "/save", method = RequestMethod.POST)
public String createEquipement(@ModelAttribute(value="equipement") @Valid EquipementModel equipement,BindingResult result, ModelMap model) {
 
    if (result.hasErrors()) {
        model.addAttribute("errors", result.getAllErrors());
        return "newequipement";
    }
        equipementService.addEquipement(equipement);
    return "redirect:home";
}
 
 
@RequestMapping(value = "/delete", method = RequestMethod.GET)
public String deleteEquipement(@ModelAttribute EquipementModel equipement, ModelMap model) {
    equipementService.deleteEquipement(equipement);
    return "redirect:home";
}
Et donc le problème, lorsque je vais sur la webapp donc par exemple localhost:8080/home (ou /add)

J'ai ce message :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
HTTP Status 500 - Handler processing failed; nested exception is java.lang.StackOverflowError
 
type Exception report
 
message Handler processing failed; nested exception is java.lang.StackOverflowError
 
description The server encountered an internal error that prevented it from fulfilling this request.
 
exception
 
org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.StackOverflowError
	org.springframework.web.servlet.DispatcherServlet.triggerAfterCompletionWithError(DispatcherServlet.java:1302)
	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:977)
	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:969)
	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:860)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
	org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
 
root cause
 
java.lang.StackOverflowError
	java.security.AccessController.doPrivileged(Native Method)
	java.io.FilePermission.init(FilePermission.java:209)
	java.io.FilePermission.<init>(FilePermission.java:285)
	sun.net.www.protocol.file.FileURLConnection.getPermission(FileURLConnection.java:225)
	sun.net.www.protocol.jar.JarFileFactory.getPermission(JarFileFactory.java:156)
	sun.net.www.protocol.jar.JarFileFactory.getCachedJarFile(JarFileFactory.java:126)
	sun.net.www.protocol.jar.JarFileFactory.get(JarFileFactory.java:81)
	sun.net.www.protocol.jar.JarURLConnection.connect(JarURLConnection.java:122)
	sun.net.www.protocol.jar.JarURLConnection.getInputStream(JarURLConnection.java:150)
	java.net.URL.openStream(URL.java:1041)
	java.lang.ClassLoader.getSystemResourceAsStream(ClassLoader.java:1372)
	java.lang.Class.getResourceAsStream(Class.java:2109)
	org.springframework.core.LocalVariableTableParameterNameDiscoverer.inspectClass(LocalVariableTableParameterNameDiscoverer.java:101)
	org.springframework.core.LocalVariableTableParameterNameDiscoverer.getParameterNames(LocalVariableTableParameterNameDiscoverer.java:87)
	org.springframework.core.PrioritizedParameterNameDiscoverer.getParameterNames(PrioritizedParameterNameDiscoverer.java:65)
	org.springframework.data.mapping.model.PreferredConstructorDiscoverer.buildPreferredConstructor(PreferredConstructorDiscoverer.java:109)
	org.springframework.data.mapping.model.PreferredConstructorDiscoverer.<init>(PreferredConstructorDiscoverer.java:74)
	org.springframework.data.mapping.model.BasicPersistentEntity.<init>(BasicPersistentEntity.java:92)
	org.springframework.data.mongodb.core.mapping.BasicMongoPersistentEntity.<init>(BasicMongoPersistentEntity.java:75)
	org.springframework.data.mongodb.core.mapping.MongoMappingContext.createPersistentEntity(MongoMappingContext.java:91)
	org.springframework.data.mongodb.core.mapping.MongoMappingContext.createPersistentEntity(MongoMappingContext.java:39)
	org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:299)
	org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.createAndRegisterProperty(AbstractMappingContext.java:489)
	org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.doWith(AbstractMappingContext.java:446)
	org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:689)
	org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:314)
	org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.createAndRegisterProperty(AbstractMappingContext.java:489)
	org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.doWith(AbstractMappingContext.java:446)
	org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:689)
	org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:314)
	org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.createAndRegisterProperty(AbstractMappingContext.java:489)
	org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.doWith(AbstractMappingContext.java:446)
	org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:689)
	org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:314)
	org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.createAndRegisterProperty(AbstractMappingContext.java:489)
	org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.doWith(AbstractMappingContext.java:446)
Ce qui est fort, c'est que lorsque je rafraichi la page, j'arrive bien sur la page comme si rien n'était, c'est uniquement lorsque je restart le serveur.

Si jamais j'enleve le modèle InterventionModel, tout fonctionne noramelement.

Est-ce que quelqu'un aurait une idée please?

Merci beaucoup.