150,695 questions
1118
votes
65
answers
1.2m
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.
555
votes
25
answers
744k
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....
460
votes
20
answers
554k
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 ...
395
votes
17
answers
488k
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 ...
389
votes
55
answers
1.3m
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?
******...
358
votes
11
answers
621k
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 = [...
337
votes
20
answers
633k
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 ...
315
votes
22
answers
537k
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 ...
300
votes
34
answers
674k
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....
293
votes
29
answers
447k
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
...
284
votes
4
answers
188k
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()
...
251
votes
55
answers
992k
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....
242
votes
36
answers
626k
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....
241
votes
16
answers
308k
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 ...
228
votes
28
answers
330k
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
11
answers
244k
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 than ...
215
votes
25
answers
418k
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....
211
votes
13
answers
328k
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....
205
votes
11
answers
379k
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 ...
202
votes
4
answers
212k
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 ...
199
votes
9
answers
289k
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 ...
196
votes
5
answers
239k
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: $...
186
votes
16
answers
261k
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 ...
184
votes
12
answers
177k
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) ...
183
votes
29
answers
450k
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": ...