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.
Related
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?
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
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.
I am setting up a Configuration manager using Spring cloud config, I'm having an issue where the Client is not picking up the property source (Hosted HTTPS Server URI) when I deploy the application to a Docker container on Azure, works when the same code is running on Localhost which picks the same URI, thoughts on how to proceed ?
I have provided all the required parameters including the app name and the SERVER URI along with the active profile (dev) and label (1.0) in the bootstrap.properties, I also tried disabling security by setting management.security.enabled to false thinking it is a Security issue, but nothing seems to locate the property source. (Worst case is the HTTPS server URI seems to be located when the client is running locally), It is only when the code is containerized using Docker and deployed to Azure, it is showing this behavior. Any help greatly appreciated !
P.S - Working on latest snapshots of SpringBoot 2.1.3 and latest snapshot of Spring Cloud starter 2.1.1, No problems with any of the dependencies I have added.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.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>
<org.apache.commons.version>3.5</org.apache.commons.version>
<java.version>1.8</java.version>
<lombok.version>1.16.12</lombok.version>
<apt.version>1.1.3</apt.version>
<querydsl.version>4.1.4</querydsl.version>
<log4j-api.version>2.6</log4j-api.version>
</properties>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
<version>2.1.1.RELEASE</version>
</dependency>
bootstrap.properties
spring.cloud.config.uri=example.org
spring.application.name=MyApp
spring.profiles.active=dev
spring.cloud.config.profile=dev
spring.cloud.config.label=1.0
application.properties
management.endpoints.web.exposure.include=*
Expected when running on Localhost
2019-04-03 14:48:42.499 INFO 50217 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : example.org
2019-04-03 14:48:43.961 INFO 50217 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Located environment: name=MyApp, profiles=[dev], label=1.0, version=null, state=null
2019-04-03 14:48:43.961 INFO 50217 --- [ main] b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource {name='configService', propertySources=[MapPropertySource {name='MyApp-dev'}]}
2019-04-03 14:48:43.965 INFO 50217 --- [ main] c.s.c.backroom.claims.ClaimsApplication : The following profiles are active: dev
2019-04-03 14:48:44.985 INFO 50217 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-04-03 14:48:45.135 INFO 50217 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 138ms. Found 17 repository interfaces.
2019-04-03 14:48:45.929 INFO 50217 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=1f523ae6-9bf7-3733-ae13-ea87a67e1564
201
Actual Result when running on Docker container on Azure
2019-04-03T17:35:03.470926214Z 2019-04-03 17:35:03.470 INFO 8 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : example.org
2019-04-03T17:35:09.723760869Z 2019-04-03 17:35:09.723 WARN 8 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Could not locate PropertySource: Could not extract response: no suitable HttpMessageConverter found for response type [class org.springframework.cloud.config.environment.Environment] and content type [text/html;charset=ISO-8859-1]
2019-04-03T17:35:09.752928427Z 2019-04-03 17:35:09.752 INFO 8 --- [ main] c.s.c.backroom.claims.ClaimsApplication : The following profiles are active: dev
2019-04-03T17:35:19.974721803Z 2019-04-03 17:35:19.971 INFO 8 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
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!