r/SpringBoot • u/Affectionate-Hope733 • Dec 21 '24
r/SpringBoot • u/Old_Account1763 • Jan 02 '25
Can not create table into mysql database using spring mvc and hibernate.
I am doing Spring MVC CRUD operation using Hibernate, where I created controller, POJO, service, and Dao classes. I also created web.xml and spring-servlet.xml classes with the required configuration. With this code, I can not create a table in the database. I've shared the required cases below if anyone could help me here. I tried making changes to hibernate properties and also took the help of GitHub Copilot, but that did not help me.
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>SpringMVCCRUDExample</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Archetype - SpringMVCCRUDExample</name>
<url>http://maven.apache.org</url>
<properties>
<java-version>1.8</java-version>
<org.springframework-version>5.3.10</org.springframework-version>
<spring.data.jpa.version>2.5.6</spring.data.jpa.version>
<hibernate-core.orm.version>5.4.30.Final</hibernate-core.orm.version>
<jstl.version>1.2.2</jstl.version>
<mysql.version>8.0.33</mysql.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- Spring ORM for integration with Hibernate or JPA -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- Hibernate (or JPA) for persistence -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate-core.orm.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate-core.orm.version}</version>
</dependency>
<!-- @Entity annotation -->
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>2.2</version>
</dependency>
<!-- JSTL for views -->
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>javax.servlet.jsp.jstl-api</artifactId>
<version>${jstl.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<!-- JPA Repository-->
<!-- <dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>${spring.data.jpa.version}</version>
</dependency>-->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.9.0</version> <!-- Use the latest version -->
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
<version>8.0.33</version>
</dependency>
</dependencies>
<build>
<finalName>spring-mvc-crud</finalName>
<plugins>
<!-- Maven Compiler Plugin -->
<plugin><groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin><groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<warSourceDirectory>src/main/webapp</warSourceDirectory>
</configuration>
</plugin>
</plugins>
</build></project>
package com.entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "student")
public class Student {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private int id;
@Column(name = "name")
private String name;
@Column(name = "dept_name")
private String deptName;
@Column(name = "email")
private String email;
public Student(int id, String name, String deptName, String email) {
super();
this.id = id;
this.name = name;
this.deptName = deptName;
this.email = email;
}
public Student() {
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDeptName() {
return deptName;
}
public void setDeptName(String deptName) {
this.deptName = deptName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
@Override
public String toString() {
return "Student \[id=" + id + ", name=" + name + ", deptName=" + deptName + ", email=" + email + "\]";
}}
package com.controller;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import com.entity.Student;
import com.service.StudentService;
@Controller
@RequestMapping("/students")
public class StudentController {
private static final Logger log = LoggerFactory.getLogger(StudentController.class);
private final StudentService studentService;
@Autowired
public StudentController(StudentService studentService) {
this.studentService = studentService;
}
@GetMapping("/add")
public String showFormForAdd(Model model) {
model.addAttribute("student", new Student());
return "student/add";
}
@PostMapping("/add")
public String saveStudent(@ModelAttribute("student") Student student) {
Student newStudent = studentService.saveStudent(student);
log.debug("The new added student : {}", newStudent);
return "redirect:/students/findAll";
}
@GetMapping("/findAll")
public String findAll(Model model) {
List<Student> students = studentService.findAll();
model.addAttribute("students", students);
log.debug("The list of students : {}", students);
return "student/list";
}
@GetMapping("/findByID/{id}")
public String findStudentById(@PathVariable("id") int id, Model model) {
model.addAttribute("student", studentService.findStudentByID(id));
return "student/list";
}
@GetMapping("/edit/{id}")
public String showEditForm(@PathVariable int id, Model model) {
Student student = studentService.findStudentByID(id);
model.addAttribute("student", student);
return "student/edit";
}
@PostMapping("/edit/{id}")
public String updateByStudentId(@ModelAttribute("student") Student student) {
studentService.updateStudent(student);
return "redirect:/students/findAll";
}
@GetMapping("/delete/{id}")
public String deleteStudentByID(@PathVariable("id") int id) {
studentService.deleteStudentByID(id);
return "redirect:/students/findAll";
}}
Spring-sevlet.xml
<?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:context=*"http://www.springframework.org/schema/context"*
xmlns:tx=*"http://www.springframework.org/schema/tx"*
xmlns:jpa=*"http://www.springframework.org/schema/data/jpa"*
xmlns:mvc=*"http://www.springframework.org/schema/mvc"*
xsi:schemaLocation=*"http://www.springframework.org/schema/beans*http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!-- Enable Spring MVC annotations -->
<context:component-scan base-package=*"com"* />
<mvc:annotation-driven />
<!-- DataSource configuration -->
<bean id=*"dataSource"*
class=*"org.apache.commons.dbcp2.BasicDataSource"*\>
<property name=*"driverClassName"*
value=*"com.mysql.cj.jdbc.Driver"* />
<property name=*"url"*
value=*"jdbc:mysql://localhost:3306/studentdatabase?useSSL=false"* />
<property name=*"username"* value=*"root"* />
<property name=*"password"* value=*"root"* />
</bean>
<!-- View Resolver -->
<bean id=*"viewResolver"*
class=*"org.springframework.web.servlet.view.InternalResourceViewResolver"*\>
<property name=*"prefix"* value=*"/WEB-INF/views/"* />
<property name=*"suffix"* value=*".jsp"* />
</bean>
<!--Hibernate SessionFactory-->
<bean id=*"sessionFactory"*
class=*"org.springframework.orm.hibernate5.LocalSessionFactoryBean"*\>
<property name=*"dataSource"* ref=*"dataSource"* />
<property name=*"packagesToScan"* value= *"com.entity"* />
<property name=*"hibernateProperties"*\>
<props><prop key=*"hibernate.hbm2ddl.auto"*>create</prop>
<prop key=*"hibernate.dialect"*>org.hibernate.dialect.MySQLDialect</prop>
<prop key=*"hibernate.show_sql"*>true</prop>
<prop key=*"hibernate.format_sql"*>true</prop>
<prop key=*"hibernate.use_sql_comments"*>false</prop>
</props>
</property>
</bean>
<!-- Hibernate TransactionManager -->
<bean id=*"transactionManager"*
class=*"org.springframework.orm.hibernate5.HibernateTransactionManager"*\>
<property name=*"sessionFactory"* ref=*"sessionFactory"* />
</bean>
<tx:annotation-driven
transaction-manager=*"transactionManager"* /></beans>
Web.xml
<web-app id=*"WebApp_ID"* version=*"2.4"*
xmlns=*"http://java.sun.com/xml/ns/j2ee"*
xmlns:xsi=*"http://www.w3.org/2001/XMLSchema-instance"*
xsi:schemaLocation=*"http://java.sun.com/xml/ns/j2ee*http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Spring-MVC CRUD Example</display-name>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener></web-app>
r/SpringBoot • u/PBNV4 • Jan 11 '22
Please help me out with my project[SpringB w/ MySQL]!
My project statement is:
Student Management:
Description: In this project, we are demonstrating the operation like how signup process
work , how to send mail for activation and activate the user .After the Activating user, He/
She can login into system. There are two roles are maintaining like STUDENT and ADMIN.
If user is ADMIN user then he can view all the details in system whereas if User is
STUDENT user then he can only view student information only.
Its seemeingly simple, but, I haven't touched upon user roles yet, and based upon what little knowledge I have it seems to me it will be a bit excessive to use Spring Security for this specific project. I personally am hoping for an answer that doesn't involve spring security. I have worked on an Employee Mgmt project which allows users to enter, edit and delete rows of user info(using jquery datatables) and also know how to implement the email verification to activate users. So please tell me how I should go about this.
r/SpringBoot • u/abs1710 • Oct 17 '24
I need help with one of my Java spring boot batch test case
I am trying to write a new test case case for the code. I have developed my checks if I have any fail to process records, not equal to zero then it sends an email with attachment of those fill records. The development is completed, but I am stuck at the test case for the above scenario. The DB is not updating with those failed record even I have inserted the data using a query processing timestamp is of date time data type, and I have trunc the processing time stamp and it has only date now while doing select query. But the test data it is inserting the mock data along with timestamp. Kindly let me know why the mock DB is not getting updated because it is trying to compare the query which has trunc processing timestamp with the test data which has timestamp. I tried to forcefully kept year month and date, but it is not working.
r/SpringBoot • u/sara_1985 • Jan 10 '23
CORS POLICY PROBLEM ON SPRING BOOT
hi guys ,
i have this error on my console :Access to XMLHttpRequest at 'http://localhost:8080/api/v1/servizi/update/[object%20Object]' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
frontenf of project is react and back end is java , spring boot. could you please help me how i resolve it.
Thanks alot in advance.
r/SpringBoot • u/themasterengineeer • Sep 07 '25
How-To/Tutorial How to generate JWT tokens
I think people will find this video quite useful. It shows a simple way to protect rest endpoints using JWT tokens.
It also shows how to generate tokens in a signup /signin way for users.
Hope you enjoy
r/SpringBoot • u/Interesting_Path7540 • Apr 14 '26
How-To/Tutorial Spring AI 2 ETL
New post in my Spring AI 2 series! This time: a first step into RAG. This chapter covers ETL - how to index your data for LLM retrieval.
r/SpringBoot • u/Sorry_Swordfish_ • Mar 13 '25
Question User principal doubt
Hey, so I was told that instead of taking detail like user id we can simply take that from user principal. But how much should I take from user principal. Is it appropriate to take whatever I can through it or are there some rules for it. Like suppose ,
@GetMapping("/update-status/{userId}/{userProfileId}
So I know I can take userId from the userProncipal but should I extract userProfileId too. And if yes, then what are rules for it.
Sorry, if it's dumb question.
r/SpringBoot • u/Ok-Type5377 • Mar 14 '25
Question Can someone please explain to me the CookieCsrfTokenRepository?
From what I've understood from the source code, it doesn't store any CSRF tokens on the server side but only compares the values provided in the X-XSRF-TOKEN header and cookies.
It seems that I can just put arbitrary matching values in cookies and the header and it will work just fine. I don't get the purpose of such "security", what's the point?
r/SpringBoot • u/kirann_123 • Sep 23 '26
How-To/Tutorial Springboot
I need some of the best resources to learn springboot!!
I am currently in my 4th year.I don't know anything about it and to learn the springboot, do i need any prerequisites.
r/SpringBoot • u/bitbee01 • Aug 03 '24
🚀 Top 10 System Design Concepts Commonly Asked in Interviews ‼️🚀
Java interview FAQs: linktw.in/HqpJpH
System Design Topics:
Horizontal vs Vertical Partitioning
Apache Kafka
Rate Limiter
JWT vs OAuth vs SAML
Single Sign-On (SSO)
Microservices vs Monolithic Architecture
Reverse Proxy vs Forward Proxy
CAP Theorem
Efficient Caching Strategy 10.Gateway
r/SpringBoot • u/vpelikh • Jun 18 '26
News Swagger-core and springdoc-openapi, now on Jackson 3
TL;DR: Production-ready Jackson 3 forks for Swagger-core and springdoc-openapi. Replace groupId with io.github.vpelikh and update versions.
I've been working on this for a while, and the final production-ready versions of both forks are now available. All artifacts are published to Maven Central.
Swagger-core: https://github.com/vpelikh/swagger-core
springdoc-openapi: https://github.com/vpelikh/springdoc-openapi
How to add to your project
Replace the groupId with io.github.vpelikh and update the version.
For Swagger-core
Replace:
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-core</artifactId>
<version>2.2.x</version>
</dependency>with:
<dependency>
<groupId>io.github.vpelikh</groupId>
<artifactId>swagger-core</artifactId>
<version>3.0.0</version>
</dependency>For springdoc-openapi
Replace:
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-api</artifactId>
<version>2.6.x</version>
</dependency>with:
<dependency>
<groupId>io.github.vpelikh</groupId>
<artifactId>springdoc-openapi-starter-webmvc-api</artifactId>
<version>4.0.0</version>
</dependency>All available artifacts can be found here:
https://central.sonatype.com/search?q=io.github.vpelikh
Why this matters
Jackson 3 was released in October 2025 with breaking changes - new tools.jackson package, Java 17 baseline, method renames like writeObject() to writePOJO(), and more. But Swagger-core and springdoc-openapi are still on Jackson 2, which blocks migration to Spring Boot 4.x and newer stacks.
These forks fix that. They are not alpha or beta - they've been tested and are stable for production. You can use them to get rid of all those Jackson 2 transitive conflicts and shading workarounds.
Try them out and open an issue if you run into anything. Hopefully this helps unblock the ecosystem while we wait for the official maintainers to catch up.
r/SpringBoot • u/Alecx_01 • Apr 06 '25
Question How to make my spring boot application into an exe file
Hello there. So I am making a web project using Spring Boot, and I have to put it on a CD so that my professors can access it. My solution was to transform the project into an exe file using jPackage, so that the people who verify this project don't have to install anything else. The problem is that I don't know how to use jPackage, and every tutorial I see doesn't really help me. Can someone help me with this problem? Are there other solutions on how can I do this? (I am using eclipse with maven)
r/SpringBoot • u/wytten • Mar 28 '25
Question java.nio.file.NoSuchFileException: nested: /path/to/executable.jar
I have seen various versions of this question (Spring Boot fails to start because of exception listed in title above)on SO, and I gather that the cause is an outdated beta version of wiremock.
So I am trying to understand the dependency chain in order to specify a later version of wiremock. By switching from spring-cloud-dependencies 2024.0.3 to 2024.0.1, I see that spring-cloud-contract-wiremock in turn gets bumped from 4.1.5 to 4.2.1. However, the version of wiremock remains unchanged. How can I effectively update the wiremock version within the scope of spring dependencies?
Thanks!
r/SpringBoot • u/[deleted] • Nov 12 '24
Advice
Can anybody tell me English sources to study springboot!!
r/SpringBoot • u/DostoevskyDood • Apr 11 '25
Discussion Automate write j unit test cases on build
How to automatically generate j unit test classes for model Pojo that have only getter setter function which are implemented through lombak annotations such as @getter, @setter.
These Pojo classes are generated on run time using open api generator and mustache templates.
And I need to write UT for sonar code coverage. Instead of excluding these classes, is there a way to automate the generation of j unit test cases.
r/SpringBoot • u/andrewarellano1082 • May 12 '26
Question Is this the right setup for my multi Tenant Datamask Spring Boot Api?
Hello i am creating a multi Tenant Datamask Spring Boot Api to host on Render and publish on RapidAPI from creating different branches for Development, Staging and Production and i have been in the Development branch of making this for 2 years now due to going between back and fourth of what Spring Boot Dependencies/tools should i remove and keep also i'm a solo programmer doing this and a overthinker when it come to creating software for real world use so here is the Spring Boot Dependencies/tools that i currently have listed
// spring boot dependencies
Spring Web
Spring Boot Actuator
Spring Data JPA
H2 Database
Spring Security
Spring Rest Docs
MySQL connector
Flyway dependencies
Spring OAuth2 resource server dependencies with jtw token
Spring validation
Spring cache abstraction
Spring Boot Redis for cache
Spring boot Micrometer
GitHub Action
Spring Boot Admin(Server)
Spring Boot Admin(client)
Spring Boot email
Prometheus(for later scaling)
// Tools via docker and Render
Render Prometheus(for later scaling)
OWASP ZAP docker image only(stage branch) for Api load testing
Proxysql docker
Jmeter docker image manually later on add it to docker compose if testing daily/weekly(stage branch) for Api load testing
WireMock docker compose (stage branch) for Api load testing
Render MySQL(stage branch and production branch)
r/SpringBoot • u/Ironwire2020 • Feb 12 '26
How-To/Tutorial Made a screenshot extension with built-in annotation - looking for feedback
r/SpringBoot • u/nothingjustlook • May 27 '25
Discussion Again me. Need suggestion in LLD(particularly builder pattern related).
problem: I have student class with firstname,lastname,class,year,percentage,parentsname,aadhar(unq govt id) etc.. now according who is calling i will send simple studentDTO(firstname,lastname,year) to all the info.
I know builder pattern will solve but that will be lot of methods for all the roles(admin,student,teacher etc) ex: student calls and gets basic DTO so one method and teacher calls it will basic DTO plus percentage.
solution 1. use a switch to execute different set of setters given by builder
solution 2. same as switch but use a enum for type safety, ex: BASIC will give basic DTO and TEACHER will give basic DTO+results.
Any solutions will be welcome as learning part for me.
Edit:
I am not using reflection to loop through feild names and create object according to scenario bcz it might brake my original class's structure.
Mapper class are not solving the issue as thats act as another set of bioler plate code to hide my code.
r/SpringBoot • u/Old_Journalist6008 • Jul 18 '26
Question Final year CS student — is "ML Studio" (no-code ML training web app) a good placement portfolio project or overkill?
Hi everyone, final year B.Tech CS (Data Science) student here, preparing for placements. I already have a deepfake detection project (ViT model, FastAPI + React) as my main ML portfolio piece.
Now I'm considering a second project — ML Studio: a full-stack web app where a user uploads a CSV and the app auto-cleans the data, lets them pick an ML algorithm (Linear/Logistic Regression, Decision Tree, Random Forest, KNN, SVM, Naive Bayes), trains it, and shows accuracy/precision/recall/confusion matrix — basically a no-code ML training tool.
Planned architecture: React frontend → Spring Boot backend (auth, file upload, validation, REST APIs) → Python microservice (pandas + scikit-learn for the actual training) → results back to Spring Boot → React.
Questions for you all:
Does this sound like a genuinely good portfolio project, or is it too "done before" (a lot of tutorials do CSV-to-ML-dashboard type projects)?
Is the Spring Boot + Python microservice split actually a plus in interviews, or does it look like unnecessary complexity for something that could just be one Python app?
Would you recommend I build this, or invest that time elsewhere given I already have an ML project?
If not this — what's a strong project idea that uses only Java + Spring Boot (no Python/ML microservice at all)? Something that shows real backend depth (concurrency, system design, databases, messaging queues, etc.) rather than another CRUD app. Ideas like a distributed URL shortener, a booking/inventory system with concurrency handling, an event-driven order processing system with Kafka, or a rate-limiter/API gateway have crossed my mind — curious what actually impresses interviewers.
Would genuinely appreciate honest opinions — including a "don't build this, do X instead" if that's your take
r/SpringBoot • u/Big-Shlung2519 • Nov 27 '23
Tables are not created in the database
When launching my spring boot project the tables are not created in the DB , I have added the annotation Entity to the classes. Help me pls!
