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/sch
The problem it's in this class:
@ComponentScan
@EnableAutoConfiguration
public class Application {
public static void main(String[] args) {
//SpringApplication.run(Application.class, args);
SpringApplication.run(ScheduledTasks.class, args);
}
}
The correct way to launch your application is:
@SpringBootApplication
@EnableScheduling
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
An other cause of this problem is corruption of maven repository jars so you can use the following command to solve the problem :
mvn dependency:purge-local-repository
Clear repository is one possible solution.
Windows -> delete all subfolders in the maven repository:
C:\Users\YourUserName.m2\repository
If you package it as a single jar and it's non web app try to load app context as below.
@SpringBootApplication
ApplicationContext ctx = new AnnotationConfigApplicationContext(Main.class);
Or use below plugin to package as a single jar
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
you can specify the external configs by using below command to run
java -jar myproject.jar --spring.config.location=classpath:/default.properties,classpath:/override.properties
/http://docs.spring.io/spring-boot/docs/current/reference/htmlboot-features-external-config.html#boot-features-external-config-application-property-files
Note that if you are passing the properties as arguments then don't include @PropertySource("classpath:test.properties")
it will override the parameters
Try this
@Configuration
@ComponentScan
@EnableAutoConfiguration
public class Application {
public static void main(String[] args) {
SpringApplication.run(ScheduledTasks.class, args);
}
}
Adding the annotation @SpringBootApplication
Before the starter class fixed this problem for me (so in essence, this error message can mean "you don't have a @SpringBootApplication
marked class anywhere, you need at least one)
@SpringBootApplication
public class AppStarter {
public static void main(String[] args) {
SpringApplication.run(AppStarter.class, args);
}
}