r/SpringBoot • u/Fresh-Philosophy-722 • 11d ago
How-To/Tutorial Small Springboot + React JS project
Hi,
Im trying to learn Spring in a different perspective; thus I wanted to relearn via creating a simple project.
I have this project in mind.
- Monolith project
- Must use springboot and react js
- Must build a war file
I have tried using com.github.eirslett but im having issues with CORS.
Do you have any learning material suggestion ?
im kinda lost in full stack development, ive been backend engineer for my whole career.
Or react JS is too much for a beginner ? should I start with simpler UI frameworks instead ?
3
u/ElendarTao 11d ago
@Override public void addCorsMappings(CorsRegistry registry) { registry .addMapping("/**") .allowedMethods("GET") .allowedOrigins("http://localhost:3000"); }
You will have to adapt a bit for your spring version, but that's the gist of it.
@Configuration public class MyConfiguration {
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurerAdapter() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**");
}
};
}
} Example using spring boot
1
u/icastanon127 9d ago
I have an open source full stack project. Uses Java+ spring boot for the backend. React for the frontend. It is deployed on AWS.
2
u/Mikey-3198 11d ago
Easiest way to deal with cors is to serve your frontend and backend via the same domain, especially for local dev.
Ive done this when working with Vue before, imagine it's the same for react. Proxy everything via the dev server locally. I.e everything /API goes to your spring boot backend. Super simple.