I'm trying to create the simplest spring-boot with reactJS project. I had the back-end working (the postgres connection and /api route working). I created the project with spring initializer and included thymeleaf at that time, based on the tutorials I was following. But then when I started adding ReactJS I got a SAXParser error. Googling this resulted in several resources telling me that reactJS and Thymeleaf don't work well together. I'm not familiar with either. I tried removing Thymeleaf from the dependencies in gradle, but it is somehow still being pulled in.
The tutorial I'm following is : https://stormpath.com/blog/crud-application-react-spring-boot-user-authentication
The error I get is :
org.xml.sax.SAXParseException: Open quote is expected for attribute "employee3" associated with an element type "Employee".
I added the employee1, employee2, etc. in different parts to try to help me find the area where the error was happening. Before that there were multiple things just named 'employee' so I had no idea where the error was.
Here is index.html:
<!DOCTYPE html>
<html>
<head>
<title>React + Spring</title>
</head>
<body>
<div id='root'></div>
<script src="link-to-fb.me.stack.overflow.doesn't.like/fb.me/react-15.0.1.js"></script>
<script src="link-to-fb.me.stack.overflow.doesn't.like//react-dom-15.0.1.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.min.js"></script>
<script type="text/babel">
var Employee = React.createClass({
render: function() {
return (
<tr>
<td>{this.props.employee1.name}</td>
<td>{this.props.employee1.age}</td>
<td>{this.props.employee1.years}</td>
</tr>);
}
});
var EmployeeTable = React.createClass({
render: function() {
var rows = [];
this.props.employees.forEach(function(employee2) {
rows.push(<Employee employee3={employee2} />);
});
return (
<table>
<thead>
<tr>
<th>Name</th><th>Age</th><th>Years</th>
</tr>
</thead>
<tbody>{rows}</tbody>
</table>);
}
});
var EMPLOYEES = [
{name: 'Joe Biden', age: 45, years: 5},
{name: 'President Obama', age: 54, years: 8},
{name: 'Crystal Mac', age: 34, years: 12},
{name: 'James Henry', age: 33, years: 2}
];
ReactDOM.render(
<EmployeeTable employees={EMPLOYEES}/>, document.getElementById('root')
);
</script>
</body>
</html>
Also, and this may be a separate question, what is the proper directory structure for a spring-boot project with ReactJS? And if I remove thymeleaf, will I have to change my directory structure? Currently it is this:
/src
/main
/java
/js
app.js
/resources
/static
/templates
index.html
application.properties
and the Controller is
@Controller
public class HomeController {
@RequestMapping(value = "/")
public String index() {
return "index";
}
}
So that localhost:8080 resolves to the index.html.
Here's my gradle file :
buildscript {
ext {
springBootVersion = '1.5.8.RELEASE'
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
group = 'com'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-data-rest')
compile("org.springframework.boot:spring-boot-devtools")
runtime('org.postgresql:postgresql')
testCompile('org.springframework.boot:spring-boot-starter-test')
}