Use Spring Boot get entity from Oracle DataBase not work - java

I want to use Spring boot get entity from Oracle DB(Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production)
when i use repository findById method and toString in Console, it only return like this
LogReturnEmail [createDtm=, fileName=, forwardResult=, forwardTo=, id=f6a70923-973a-47ac-98a0-34200d4ddacb, mailSubject=, messageNo=, messageType=, sellerCompid=]
only id column have value.but i want to get all value.
Main class
#SpringBootApplication
public class Demo2Application implements ApplicationRunner {
#Autowired
private LogReturnEmailRepository repo2;
public static void main(String[] args) {
SpringApplication.run(Demo2Application.class, args);
}
#Override
public void run(ApplicationArguments args) throws Exception {
Optional<LogReturnEmail> xml = repo2.findById("f6a70923-973a-47ac-98a0-34200d4ddacb");
System.out.println(xml.get());
}
}
Repository
#Repository
public interface LogReturnEmailRepository extends JpaRepository<LogReturnEmail, String> {
}
LOG_RETURN_EMAIL entity
/**
* The persistent class for the LOG_RETURN_EMAIL database table.
*
*/
#Entity
#Table(name="LOG_RETURN_EMAIL")
#NamedQuery(name="LogReturnEmail.findAll", query="SELECT l FROM LogReturnEmail l")
public class LogReturnEmail implements Serializable {
private static final long serialVersionUID = 1L;
#Column(name="CREATE_DTM")
private String createDtm;
#Column(name="FILE_NAME")
private String fileName;
#Column(name="FORWARD_RESULT")
private String forwardResult;
#Column(name="FORWARD_TO")
private String forwardTo;
#Id
#Column(name="ID")
private String id;
#Column(name="MAIL_SUBJECT")
private String mailSubject;
#Column(name="MESSAGE_NO")
private String messageNo;
#Column(name="MESSAGE_TYPE")
private String messageType;
#Column(name="SELLER_COMPID")
private String sellerCompid;
//commented out get/set method for brevity
hibernate configurations
spring.jpa.hibernate.ddl-auto=none
spring.jpa.database-platform=org.hibernate.dialect.Oracle9iDialect
spring.datasource.url=
spring.datasource.username=
spring.datasource.password=
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
<relativePath />
</parent>
<groupId>com.example</groupId>
<artifactId>demo2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo2</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.0.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
console log
2019-05-30 09:12:53.167 INFO 13668 --- [ restartedMain] org.hibernate.Version : HHH000412: Hibernate Core {5.3.9.Final}
2019-05-30 09:12:53.168 INFO 13668 --- [ restartedMain] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2019-05-30 09:12:53.241 INFO 13668 --- [ restartedMain] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.4.Final}
2019-05-30 09:12:53.325 INFO 13668 --- [ restartedMain] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.Oracle9iDialect
2019-05-30 09:12:53.749 INFO 13668 --- [ restartedMain] o.h.h.i.QueryTranslatorFactoryInitiator : HHH000397: Using ASTQueryTranslatorFactory
2019-05-30 09:12:53.783 INFO 13668 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2019-05-30 09:12:54.006 INFO 13668 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2019-05-30 09:12:54.020 INFO 13668 --- [ restartedMain] com.example.demo.Demo2Application : Started Demo2Application in 2.115 seconds (JVM running for 2.691)
Hibernate:
select
logreturne0_.id as id1_0_0_,
logreturne0_.create_dtm as create_dtm2_0_0_,
logreturne0_.file_name as file_name3_0_0_,
logreturne0_.forward_result as forward_result4_0_0_,
logreturne0_.forward_to as forward_to5_0_0_,
logreturne0_.mail_subject as mail_subject6_0_0_,
logreturne0_.message_no as message_no7_0_0_,
logreturne0_.message_type as message_type8_0_0_,
logreturne0_.seller_compid as seller_compid9_0_0_
from
log_return_email logreturne0_
where
logreturne0_.id=?
LogReturnEmail [createDtm=, fileName=, forwardResult=, forwardTo=, id=f6a70923-973a-47ac-98a0-34200d4ddacb, mailSubject=, messageNo=, messageType=, sellerCompid=]
2019-05-30 09:12:54.079 INFO 13668 --- [ Thread-10] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2019-05-30 09:12:54.080 INFO 13668 --- [ Thread-10] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2019-05-30 09:12:54.088 INFO 13668 --- [ Thread-10] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
TABLE COLUMN NAME
ID
SELLER_COMPID
MESSAGE_NO
MAIL_SUBJECT
CREATE_DTM
FORWARD_TO
FORWARD_RESULT
FILE_NAME
MESSAGE_TYPE

Verify your Java Entity class datatypes and Oracle DATA_TYPE. This issue mostly occurs when data type mismatch.

Related

Can't Start the Spring Boot Application

I am trying to connect the database in my spring boot project. I have already created a database using phpMyAdmin. The MySQL server is running on port 3307.
But I couldn't run the application.
Here are the related files
pom.xml file is as following
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>LMS</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>LMS</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
application.properties file is as following
spring.datasource.url=jdbc:mysql://localhost:3307/lms?useUnicode=true&useJDBCCompliantTimezone
Shift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
server.error.whitelabel.enabled=false
server.port=8080
spring.datasource.username=root
spring.datasource.password=pasindu
spring.main.web-application-type=none
spring.jpa.open-in-view=false
spring.thymeleaf.cache=false
api.base.path = http://localhost:8080
Here are the Logs in Spring Boot console
2022-12-08T00:23:21.986+05:30 INFO 27872 --- [ main] com.example.LMS.LmsApplication : Starting LmsApplication using Java 17.0.4.1 with PID 27872 (C:\Users\Pasindu_112247\eclipse-workspace\LMS.zip_expanded\LMS\target\classes started by Pasindu_112247 in C:\Users\Pasindu_112247\eclipse-workspace\LMS.zip_expanded\LMS)
2022-12-08T00:23:21.990+05:30 INFO 27872 --- [ main] com.example.LMS.LmsApplication : No active profile set, falling back to 1 default profile: "default"
2022-12-08T00:23:22.500+05:30 INFO 27872 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-12-08T00:23:22.568+05:30 INFO 27872 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 57 ms. Found 1 JPA repository interfaces.
2022-12-08T00:23:22.950+05:30 INFO 27872 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2022-12-08T00:23:23.157+05:30 INFO 27872 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Added connection com.mysql.cj.jdbc.ConnectionImpl#3f0d6038
2022-12-08T00:23:23.160+05:30 INFO 27872 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2022-12-08T00:23:23.214+05:30 INFO 27872 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2022-12-08T00:23:23.260+05:30 INFO 27872 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 6.1.5.Final
2022-12-08T00:23:23.410+05:30 WARN 27872 --- [ main] org.hibernate.orm.deprecation : HHH90000021: Encountered deprecated setting [javax.persistence.sharedCache.mode], use [jakarta.persistence.sharedCache.mode] instead
2022-12-08T00:23:23.636+05:30 INFO 27872 --- [ main] SQL dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
2022-12-08T00:23:24.274+05:30 INFO 27872 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2022-12-08T00:23:24.282+05:30 INFO 27872 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2022-12-08T00:23:24.787+05:30 INFO 27872 --- [ main] com.example.LMS.LmsApplication : Started LmsApplication in 3.204 seconds (process running for 3.63)
2022-12-08T00:23:24.794+05:30 INFO 27872 --- [ionShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2022-12-08T00:23:24.799+05:30 INFO 27872 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2022-12-08T00:23:24.811+05:30 INFO 27872 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
How do I fix this?

Unable to connect to MySQL database from SpringBoot

I am trying to connect to the mySQL database from my Spring Boot application. However it is showing error when I am trying to run it.
How can I resolve this?
The error
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
Adding code snippets from my files
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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.nkamanoo.springboot</groupId>
<artifactId>course-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Java Brains Course API</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId> org.springframework.boot </groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
<version>8.0.19</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
</project>
application.properties
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://localhost:3306/db_example
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.hibernate.use-new-id-generator-mappings=false
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
stack trace
2020-02-10 13:44:34.073 INFO 63618 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.0.12.Final}
2020-02-10 13:44:34.075 INFO 63618 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2020-02-10 13:44:34.078 INFO 63618 --- [ main] org.hibernate.cfg.Environment : HHH000021: Bytecode provider name : javassist
2020-02-10 13:44:34.139 INFO 63618 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2020-02-10 13:44:34.295 INFO 63618 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2020-02-10 13:44:34.823 INFO 63618 --- [ main] org.hibernate.tool.hbm2ddl.SchemaUpdate : HHH000228: Running hbm2ddl schema update
2020-02-10 13:44:34.864 INFO 63618 --- [ main] rmationExtractorJdbcDatabaseMetaDataImpl : HHH000262: Table not found: topic
2020-02-10 13:44:34.867 INFO 63618 --- [ main] rmationExtractorJdbcDatabaseMetaDataImpl : HHH000262: Table not found: topic
2020-02-10 13:44:34.886 WARN 63618 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
2020-02-10 13:44:34.892 INFO 63618 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2020-02-10 13:44:34.910 INFO 63618 --- [ main] utoConfigurationReportLoggingInitializer :
I havent created the tables manually in sql as i thought spring.jpa.hibernate.ddl-auto=update should do it
It can be related to bad #annotations. Post your entity class to re-check.
Anyhow add the below line in your property file:
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

spring boot app shutting down without error

I am running a spring boot application with mysql, web, jpa as dependencies. I have configured the application.properties file with the database properties. The log is attached for more details below:
2018-08-16 10:02:00.746 INFO 10472 --- [ restartedMain] com.classpath.CrudApplication : Starting CrudApplication on LAPTOP-MAI0FJBD with PID 10472 (C:\Users\classpath\packt\Downloads\crud\target\classes started by classpath in C:\Users\classpath\packt\Downloads\crud)
2018-08-16 10:02:00.748 INFO 10472 --- [ restartedMain] com.classpath.CrudApplication : No active profile set, falling back to default profiles: default
2018-08-16 10:02:00.876 INFO 10472 --- [ restartedMain] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#17bd80f6: startup date [Thu Aug 16 10:02:00 IST 2018]; root of context hierarchy
2018-08-16 10:02:02.107 INFO 10472 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$437af157] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-08-16 10:02:02.370 INFO 10472 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2018-08-16 10:02:02.572 INFO 10472 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2018-08-16 10:02:02.602 INFO 10472 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2018-08-16 10:02:02.616 INFO 10472 --- [ restartedMain] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2018-08-16 10:02:02.670 INFO 10472 --- [ restartedMain] org.hibernate.Version : HHH000412: Hibernate Core {5.2.17.Final}
2018-08-16 10:02:02.671 INFO 10472 --- [ restartedMain] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2018-08-16 10:02:02.708 INFO 10472 --- [ restartedMain] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2018-08-16 10:02:02.847 INFO 10472 --- [ restartedMain] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
2018-08-16 10:02:03.377 INFO 10472 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2018-08-16 10:02:04.183 INFO 10472 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2018-08-16 10:02:04.206 INFO 10472 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2018-08-16 10:02:04.207 INFO 10472 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'dataSource' has been autodetected for JMX exposure
2018-08-16 10:02:04.210 INFO 10472 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Located MBean 'dataSource': registering with JMX server as MBean [com.zaxxer.hikari:name=dataSource,type=HikariDataSource]
2018-08-16 10:02:04.221 INFO 10472 --- [ restartedMain] com.classpath.CrudApplication : Started CrudApplication in 3.814 seconds (JVM running for 4.411)
2018-08-16 10:02:04.225 INFO 10472 --- [ Thread-10] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext#17bd80f6: startup date [Thu Aug 16 10:02:00 IST 2018]; root of context hierarchy
2018-08-16 10:02:04.228 INFO 10472 --- [ Thread-10] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
2018-08-16 10:02:04.228 INFO 10472 --- [ Thread-10] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans
2018-08-16 10:02:04.229 INFO 10472 --- [ Thread-10] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2018-08-16 10:02:04.230 INFO 10472 --- [ Thread-10] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2018-08-16 10:02:04.233 INFO 10472 --- [ Thread-10] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
Process finished with exit code 0
I have created the git repository and uploaded my code onto Github - Link to Github repo
I am also attaching the pom.xml for reference
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.classpath</groupId>
<artifactId>crud</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>crud</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
How should I be debugging this error. Kindly let me know as there is lot of magic going on here.
The condition evaluation report in the application log shows that the embedded servlet container hasn't been configured as javax.servlet.ServletRequest is not on the classpath:
ServletWebServerFactoryAutoConfiguration:
Did not match:
- #ConditionalOnClass did not find required class 'javax.servlet.ServletRequest' (OnClassCondition)
It should be on the classpath as you have a dependency on spring-boot-starter-web which pulls in tomcat-embed-core that contains all of the Servlet API classes. The application log also shows that C:\Users\classpath\.m2\repository\org\apache\tomcat\embed\tomcat-embed-core\8.5.32\tomcat-embed-core-8.5.32.jar is on the classpath.
For the jar file to be on the classpath and a class that it contains not to be found, the jar file must be corrupted. This can happen when Maven downloads the jar. Try deleting the C:\Users\classpath\.m2\repository\org\apache\tomcat\embed\tomcat-embed-core\8.5.32\ directory and rebuilding your application. This will cause Maven to download a new copy of the jar and, hopefully, to not corrupt it this time.
Finally, I was able to solve this problem. I deleted the repository directory inside .m2 and build the whole project once again. This time, it worked.

Spring Boot Application unable to start Tomcat Server

I am using Spring Tool Suite to develop a simple "Spring starter project" (spring-boot) that returns a string on receiving a get request.
The project builds successfully but instead of starting the Tomcat server, it finishes executing.
I tried running it from command line using Maven plugin and as a packaged application(jar file) but the result is same.
I am new to spring-boot and tried to follow various tutorials and searched a lot for the solution but couldn't find anything. Here's my code and console output:
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.hraichandani</groupId>
<artifactId>starter-app-2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>starter-app-2</name>
<description>Spring Boot Starter App</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<tomcat.version>8.5.23</tomcat.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
application.java
#SpringBootApplication
#RestController
public class StarterApp2Application {
public static void main(String[] args) {
SpringApplication.run(StarterApp2Application.class, args);
}
#RequestMapping(value="/greeting", method=RequestMethod.GET)
public String sayHello() {
return "Hello";
}
}
Console output
2017-11-27 04:05:49.881 INFO 17685 --- [ main] com.hraichandani.StarterApp2Application : Starting StarterApp2Application on Hiteshs-MacBook-Pro.local with PID 17685 (/Users/hitesh/Documents/spring-workspace/starter-app-2/target/classes started by hitesh in /Users/hitesh/Documents/spring-workspace/starter-app-2)
2017-11-27 04:05:49.884 INFO 17685 --- [ main] com.hraichandani.StarterApp2Application : No active profile set, falling back to default profiles: default
2017-11-27 04:05:49.916 INFO 17685 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#76b10754: startup date [Mon Nov 27 04:05:49 PST 2017]; root of context hierarchy
2017-11-27 04:05:50.838 INFO 17685 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2017-11-27 04:05:50.842 INFO 17685 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 0
2017-11-27 04:05:50.891 INFO 17685 --- [ main] com.hraichandani.StarterApp2Application : Started StarterApp2Application in 11.226 seconds (JVM running for 16.758)
2017-11-27 04:05:50.892 INFO 17685 --- [ Thread-3] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext#76b10754: startup date [Mon Nov 27 04:05:49 PST 2017]; root of context hierarchy
2017-11-27 04:05:50.895 INFO 17685 --- [ Thread-3] o.s.c.support.DefaultLifecycleProcessor : Stopping beans in phase 0
2017-11-27 04:05:50.897 INFO 17685 --- [ Thread-3] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
Any help is greatly appreciated. Thanks!

Embeded Mongodb to Spring Boot always recreate database

I need to embed Mongodb to Spring Boot application. But the way how I've done
it leads to re-creating mongo db every time I start app. I mean, my documents don't save to database persistently.
Every start I see in logs:
2017-11-22 12:03:49.188 INFO 10464 --- [ main] c.j.s.embedmongo.EmbeddedMongoBuilder : Initializing embedded MongoDB instance
2017-11-22 12:03:49.215 INFO 10464 --- [ main] d.f.embed.process.store.Downloader : Extract C:\Users\lev\.embedmongo\win32\mongodb-win32-x86_64-2008plus-3.2.1.zip : starting...
2017-11-22 12:03:49.483 INFO 10464 --- [ main] d.f.embed.process.store.Downloader : Extract C:\Users\lev\.embedmongo\win32\mongodb-win32-x86_64-2008plus-3.2.1.zip : extract mongodb-win32-x86_64-2008plus-3.2.1/bin/mongod.exe
2017-11-22 12:03:49.484 INFO 10464 --- [ main] d.f.embed.process.store.Downloader : Extract C:\Users\lev\.embedmongo\win32\mongodb-win32-x86_64-2008plus-3.2.1.zip : noting left
2017-11-22 12:03:49.484 INFO 10464 --- [ main] d.f.embed.process.store.Downloader : Extract C:\Users\lev\.embedmongo\win32\mongodb-win32-x86_64-2008plus-3.2.1.zip : finished
2017-11-22 12:03:49.484 INFO 10464 --- [ main] c.j.s.embedmongo.EmbeddedMongoBuilder : Starting embedded MongoDB instance
2017-11-22 12:03:51.180 INFO 10464 --- [ main] d.f.embed.process.runtime.Executable : start de.flapdoodle.embed.mongo.config.MongodConfigBuilder$ImmutableMongodConfig#867ba60
2017-11-22 12:03:51.383 INFO 10464 --- [ main] org.mongodb.driver.cluster : Cluster created with settings {hosts=[localhost:3707], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
2017-11-22 12:03:51.418 INFO 10464 --- [-localhost:3707] org.mongodb.driver.connection : Opened connection [connectionId{localValue:1, serverValue:1}] to localhost:3707
2017-11-22 12:03:51.419 INFO 10464 --- [-localhost:3707] org.mongodb.driver.cluster : Monitor thread successfully connected to server with description ServerDescription{address=localhost:3707, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 2, 1]}, minWireVersion=0, maxWireVersion=4, maxDocumentSize=16777216, roundTripTimeNanos=432755}
2017-11-22 12:03:51.509 INFO 10464 --- [ main] org.mongodb.driver.connection : Opened connection [connectionId{localValue:2, serverValue:2}] to localhost:3707
2017-11-22 12:03:51.939 WARN 10464 --- [ main] o.s.d.m.c.m.BasicMongoPersistentProperty : Customizing field name for id property not allowed! Custom name will not be considered!
Probably this part leads to database overwriting:
Downloader : Extract C:\Users\lev.embedmongo\win32\mongodb-win32
My Pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>guru.springframework</groupId>
<artifactId>spring-boot-mongodb</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>spring-boot-mongodb</name>
<description>Demo project for Spring Boot and Mongo DB</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
</dependency>
<dependency>
<groupId>cz.jirutka.spring</groupId>
<artifactId>embedmongo-spring</artifactId>
<version>RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Controller for storing document:
#RequestMapping("/check")
#ResponseBody
public List<Domain> check(){
System.out.println("/check");
Domain domain = new Domain(i++, "Check_"+String.valueOf(i), true);
dm.save(domain);
return dm.findAll();
}
Repository:
public interface DomainRepository extends MongoRepository<Domain, Long> {
Domain findFirstByDomain(String domain);
Domain findByDomainAndDisplayAds(String domain, boolean displayAds);
//Supports native JSON query string
#Query("{domain:'?0'}")
Domain findCustomByDomain(String domain);
#Query("{domain: { $regex: ?0 } })")
List<Domain> findCustomByRegExDomain(String domain);
}
appilcation.properties:
server.port = 8091
spring.data.mongodb.repositories.enabled=true
spring.data.mongodb.database=testme
How can I solve this isssue?
Because it's embedded, every time application is started the DB will be re-created as previous one has been deleted when the app was stopped.

Categories