I have setup a run configuration in eclipse but it's running in localhost:8080 but I want it to run in localhost:8080/demo/ but it's not working. I have attached the run configuration and application properties file
can anyone help me to run spring boot project in localhost:8080/demo/
I think that you can just add this to your properties file
server.servlet.context-path=/demo
In your controller by annotation #RequestMapping(path = "/demo") or by annotation on method #GetMapping("/demo")
Related
I'm trying to figure out how the project works.
It uses Liquibase:
The problem is that the .yaml file is not in the classpath folder so it's not accessible.
Error:
How to let Spring Boot know where is the change-log?
Use property name as
spring.liquibase.changeLog
not
liquibase.changeLog
I have created Profiles in Java class like this,
#Profile(value = "cache")
public class MapCache {
....
}
These profiles are not getting activated when spring.profiles.active used, but if i use spring.profiles.include profiles are working fine.
I would like activate profiles through properties which are added in application.properties
Note: application is running in independent jetty instance.
Any tip would be great on this.
To activate a profile via annotations you need #ActiveProfile("profileName"). The #Profile annotation is used to label an object as being a member of the profile.
you can also try to run the application and pass them as command line args
java -jar -Dspring.profiles.active={your_profile_name} application.jar
or if you run the app via maven:
mvn spring-boot:run -Dspring-boot.run.profiles={your_profile_name}
Here is an nice example I found on the internet with all the ways you can set the spring profile, it should help : https://www.baeldung.com/spring-profiles
I encountered a similar issue where SpringBoot wasn't activating the profiles set in the spring.profiles.active application property.
The issue was the result of the code base using a non standard name and location for the application property file (not my doing). Once I specified the location via the command line arg- --spring.config.location=/non/standard/location/acme.properties- the profile was activated.
I am using Spring Boot 2.2.2 with Flyway 5.2.4 and I tried to configure flyway to use a differente location for the scripts, but spring.flyway.locations=filesystem:db_other/migration/{vendor} neither flyway.locations=filesystem:db_other/migration/{vendor} configurations on application.properties worked.
When running the program, the following exception appear in the log:
FlywayMigrationScriptMissingException: Cannot find migration scripts in: [classpath:db/migration]
I already tried using Spring Boot 2.2.1, 2.2.0, 2.1.11 and Flyway 6.1.0 and 6.1.3, but the result is the same.
The default value for that property is classpath:db/migration as shown here (search for flyway).
Since you're using a different folder in the resources directory you should only need to change "filesystem" to "classpath" in your application.properties value.
Actually if was my fault: as I used to work with just spring (not spring boot) I configured my test class with the annotations #ExtendWith(SpringExtension.class) AND #ContextConfiguration(classes = { MyConfiguration.class }) instead of just use #SpringBootTest. When making this change the test worked.
I want to generate a java jar which when included on the classpath of another project will launch a periodic task that does something in the background.
This is very similar to eureka client. You include the dependency and add an annotation after which a service is started automatically to poll eureka server.
How can I do that?
Edit: I got it to work using maven, following the example provided in the comments
github.com/shauank/spring-boot/tree/master/client (client which is having taskexecutor)
github.com/shauank/spring-boot/tree/master/application (Application which uses jar created in step1)
You can use concept of Autoconfiguration. Same is used by Eureka and Config server.
Under src/main/resource create spring.factories and add following entry
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
location.to.your.executor
Your class,
pacakage location.to.your.executor
class MyExecutor{
public MyExecutor(){
//Your code for task executor
}
}
Now, above code can be build as jar and included into another spring boot project.
So, when you run another jar, spring boot will look for auto configuration onto spring.factories class and load classes defined into it.
I have a simple project with Spring Actuator, also i have a maven plugin generating git.properties (resides in classes directory).
However when i run my app, /actuator/info request shows:
{
"git": {}
}
Documentation says autoconfigure should pick up properties automatically https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#production-ready-application-info-git
My mistake, git.properties was not a 'properties' file in fact.
I didn't see {} around a file content.
after changing configuration/format to properties in git-commit-id-plugin plugin, it works
(plugin was generating git info in json)