Questions tagged [spring-boot]
Use the Spring Boot tag for questions related to spring boot framework and the features it brings to your Web application. This includes questions about configuration, embedding of the Web servers, setting up metrics, health checks, externalized configuration etc. It does not include questions about the Web server itself, Java code running in your application, or standard spring components. Tag these questions with its own tags to get the best response!
spring-boot
148,063
questions
1069
votes
64
answers
1.1m
views
How to configure port for a Spring Boot application
How do I configure the TCP/IP port listened on by a Spring Boot application, so it does not use the default port of 8080.
564
votes
31
answers
1.0m
views
How to access a value defined in the application.properties file in Spring Boot
I want to access values provided in application.properties, e.g.:
logging.level.org.springframework.web: DEBUG
logging.level.org.hibernate: ERROR
logging.file=${HOME}/application.log
userBucket.path=...
531
votes
25
answers
671k
views
How can I log SQL statements in Spring Boot?
I want to log SQL statements to a file.
I have the following properties in application.properties:
spring.datasource.url=...
spring.datasource.username=user
spring.datasource.password=1234
spring....
485
votes
18
answers
884k
views
Spring Boot: How can I set the logging level with application.properties?
This is very simple question, but I cannot find information.
(Maybe my knowledge about Java frameworks is severely lacking)
How can I set the logging level with application.properties?
And logging ...
438
votes
6
answers
231k
views
What is the purpose of mvnw and mvnw.cmd files?
When I created a Spring Boot application I could see mvnw and mvnw.cmd files in the root of the project. What is the purpose of these two files?
433
votes
19
answers
491k
views
Running code after Spring Boot starts
I want to run code after my spring-boot app starts to monitor a directory for changes.
I have tried running a new thread but the @Autowired services have not been set at that point.
I have been ...
376
votes
9
answers
176k
views
What is the difference between putting a property on application.yml or bootstrap.yml in spring boot?
What is the difference between putting a property on application.yml or bootstrap.yml in spring boot?
In logging.config case, the application works differently.
366
votes
37
answers
745k
views
org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
I am trying run a spring-boot application which uses hibernate via spring-jpa, but i am getting this error:
Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null ...
357
votes
52
answers
1.2m
views
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured
I am working on a Spring Boot Batch example with MongoDB and I have already started the mongod server.
When I launch my application, I am getting the error below.
Any pointers for this issue?
******...
339
votes
10
answers
552k
views
Spring Boot configure and use two data sources
How can I configure and use two data sources?
For example, here is what I have for the first data source:
application.properties
#first db
spring.datasource.url = [url]
spring.datasource.username = [...
322
votes
17
answers
603k
views
Setting active profile and config location from command line in Spring Boot
I have a Spring Boot application.
I have three profiles in my application-> development, staging and production. So I have 3 files
application-development.yml
application-staging.yml
application-...
310
votes
18
answers
503k
views
How do I activate a Spring Boot profile when running from IntelliJ?
I have 5 environments:
- local (my development machine)
- dev
- qc
- uat
- live
- staging
I want different application properties to be used for each environment, so I have the following ...
308
votes
22
answers
494k
views
Spring Boot - Loading Initial Data
I'm wondering what the best way to load initial database data before the application starts? What I'm looking for is something that will fill my H2 database with data.
For example, I have a domain ...
296
votes
4
answers
282k
views
What is this spring.jpa.open-in-view=true property in Spring Boot?
I saw spring.jpa.open-in-view=true property in Spring Boot documentation for JPA configuration.
Is the true default value for this property if it's not provided at all?;
What does this really do? I ...
292
votes
15
answers
421k
views
Override default Spring-Boot application.properties settings in Junit Test
I have a Spring-Boot application where the default properties are set in an application.properties file in the classpath (src/main/resources/application.properties).
I would like to override some ...
288
votes
29
answers
422k
views
How can I add a filter class in Spring Boot?
Is there any annotation for a Filter class (for web applications) in Spring Boot? Perhaps @Filter?
I want to add a custom filter in my project.
The Spring Boot Reference Guide mentioned about
...
281
votes
11
answers
234k
views
Difference between Spring MVC and Spring Boot [closed]
I have just started learning Spring. In my next step, I would like to develop bigger web applications.
Now I am wondering if I should start with Spring Boot or Spring MVC. I have already read some ...
279
votes
33
answers
593k
views
Spring boot - Not a managed type
I use Spring boot+JPA and having a problem while starting the service.
Caused by: java.lang.IllegalArgumentException: Not an managed type: class com.nervytech.dialer.domain.PhoneSettings
at org....
270
votes
24
answers
310k
views
Why does my Spring Boot App always shutdown immediately after starting?
This is my first Spring Boot code. Unfortunately, it always shuts down. I was expecting it to run continuously so that my web client can get some data from the browser.
package hello;
import org....
264
votes
4
answers
159k
views
Difference between @Mock, @MockBean and Mockito.mock()
When creating tests and mocking dependencies, what is the difference between these three approaches?
@MockBean:
@MockBean
MyService myservice;
@Mock:
@Mock
MyService myservice;
Mockito.mock()
...
252
votes
10
answers
338k
views
Spring Boot YAML configuration for a list of strings
I am trying to load an array of strings from the application.yml file. This is the config:
ignore:
filenames:
- .DS_Store
- .hg
This is the class fragment:
@Value("${ignore....
243
votes
55
answers
897k
views
Consider defining a bean of type 'package' in your configuration [Spring-Boot]
I am getting the following error:
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of method setApplicant in webService.controller....
238
votes
36
answers
598k
views
Spring Boot - Cannot determine embedded database driver class for database type NONE
This is the error that is thrown when trying to run my web app:
[INFO] WARNING: Nested in org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework....
237
votes
16
answers
289k
views
Unable to find a @SpringBootConfiguration when doing a JpaTest
I'm trying to run a simple Junit test to see if my CrudRepositories are indeed working.
The error I keep getting is:
Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration ...
234
votes
22
answers
509k
views
Add context path to Spring Boot application
I am trying to set a Spring Boot applications context root programmatically. The reason for the context root is we want the app to be accessed from localhost:port/{app_name} and have all the ...
220
votes
28
answers
259k
views
Spring Boot not serving static content
I can't get my Spring-boot project to serve static content.
I've placed a folder named static under src/main/resources. Inside it I have a folder named images. When I package the app and run it, it ...
219
votes
28
answers
586k
views
Read file from resources folder in Spring Boot
I'm using Spring Boot and json-schema-validator. I'm trying to read a file called jsonschema.json from the resources folder. I've tried a few different ways but I can't get it to work. This is my code....
219
votes
3
answers
101k
views
Spring Boot - parent pom when you already have a parent pom
Is there a specific recommended approach to the inclusion of the spring-boot parent pom into projects that already have a required parent POM?
What do you recommend for projects that need to extend ...
218
votes
6
answers
490k
views
How do I retrieve query parameters in a Spring Boot controller?
I am developing a project using Spring Boot. I've a controller which accepts GET requests.
Currently I'm accepting requests to the following kind of URLs:
http://localhost:8888/user/data/002
but ...
216
votes
20
answers
170k
views
Spring Boot application as a Service
How to configure nicely Spring Boot application packaged as executable jar as a Service in the Linux system? Is this recommended approach, or should I convert this app to war and install it into ...
213
votes
11
answers
232k
views
How do I tell Spring Boot which main class to use for the executable jar?
Execution default of goal
org.springframework.boot:spring-boot-maven-plugin:1.0.1.RELEASE:repackage
failed:
Unable to find a single main class from the following candidates
My project has more ...
207
votes
17
answers
268k
views
Classpath resource not found when running as jar
Having this problem both in Spring Boot 1.1.5 and 1.1.6 - I'm loading a classpath resource using an @Value annotation, which works just fine when I run the application from within STS (3.6.0, Windows)....
201
votes
11
answers
357k
views
Spring Boot REST service exception handling
I am trying to set up a large-scale REST services server. We're using Spring Boot 1.2.1 Spring 4.1.5, and Java 8. Our controllers are implementing @RestController and the standard @RequestMapping ...
199
votes
13
answers
279k
views
Disable all Database related auto configuration in Spring Boot
I am using Spring Boot to develop two applications, one serves as the server and other one is a client app. However, both of them are the same app that function differently based on the active profile....
197
votes
11
answers
326k
views
What is username and password when starting Spring Boot with Tomcat?
When I deploy my Spring application via Spring Boot and access localhost:8080 I have to authenticate, but what is the username and password or how can I set it? I tried to add this to my tomcat-users ...
196
votes
20
answers
356k
views
How to set base url for rest in spring boot?
I'm trying to to mix mvc and rest in a single spring boot project.
I want to set base path for all rest controllers (eg. example.com/api)
in a single place (I don't want annotate each controller with @...
196
votes
24
answers
366k
views
java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7
I am getting this exception java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7 and java.lang.NoClassDefFoundError: Could not initialize class org....
192
votes
8
answers
261k
views
Could not autowire field:RestTemplate in Spring boot application
I am getting below exception while running Spring Boot application during start up:
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'testController':
Injection ...
190
votes
30
answers
436k
views
ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean
I have written a spring batch application using Spring boot. When I am trying to run that application using command line and classpath on my local system it is running fine. However, when I tried to ...
190
votes
19
answers
440k
views
Spring Boot Remove Whitelabel Error Page
I'm trying to remove white label error page, so what I've done was created a controller mapping for "/error",
@RestController
public class IndexController {
@RequestMapping(value = "/error")
...
187
votes
4
answers
207k
views
Does application.yml support environment variables?
I tried using env variables in my application.yml configration like:
spring:
main:
show_banner: false
---
spring:
profiles: production
server:
address: $OPENSHIFT_DIY_IP
port: $...
187
votes
4
answers
193k
views
Difference between Interceptor and Filter in Spring MVC
I'm a little bit confused about Filter and Interceptor purposes.
As I understood from docs, Interceptor is run between requests. On the other hand Filter is run before rendering view, but after ...
185
votes
28
answers
420k
views
Spring Boot: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean
I am totally new to Spring and started to do the official guides from this site:
https://spring.io/guides
I'd like to do this guide:
https://spring.io/guides/gs/scheduling-tasks/
I get the following ...
181
votes
14
answers
237k
views
Spring Boot + JPA : Column name annotation ignored
I have a Spring Boot application with dependency spring-boot-starter-data-jpa. My entity class has a column annotation with a column name. For example:
@Column(name="TestName")
private ...
181
votes
10
answers
146k
views
Compilation error after upgrading to JDK 21 - "NoSuchFieldError: JCImport does not have member field JCTree qualid"
After upgrading to JDK 21, I have the following compilation error in my Spring Boot project:
Fatal error compiling: java.lang.NoSuchFieldError:
Class com.sun.tools.javac.tree.JCTree$JCImport does not ...
179
votes
1
answer
187k
views
How to determine programmatically the current active profile using Spring boot [duplicate]
Is there a way programmatically to get the current active profile within my bean?
178
votes
11
answers
161k
views
Speed up Spring Boot startup time
I have a Spring Boot application. I've added a lot of dependencies (unfortunately, looks I need all of them) and the startup time went up quite a lot. Just doing a SpringApplication.run(source, args) ...
177
votes
28
answers
424k
views
Spring Boot: Cannot access REST Controller on localhost (404)
I am trying to adapt the REST Controller example on the Spring Boot website.
Unfortunately I've got the following error when I am trying to access the localhost:8080/item URL.
{
"timestamp": ...
177
votes
10
answers
273k
views
Java Spring Boot: How to map my app root (“/”) to index.html?
How can I map my app root http://localhost:8080/ to a static index.html?
If I navigate to http://localhost:8080/index.html its works fine.
My app structure is :
My config\WebConfig.java looks like ...
175
votes
13
answers
665k
views
Spring Boot and multiple external configuration files
I have multiple property files that I want to load from classpath. There is one default set under /src/main/resources which is part of myapp.jar. My springcontext expects files to be on the classpath. ...