1. It is structured to run using normal main method of java (Jar file having main method is executed through some script).
2. Its making use of spring.xml(applicationContext.xml) files with spring-context-2.5.xsd
3. Uses properties file for all configurations.
1. Does this project needs to be migrated to spring-boot application for migrating to/creating docker image?
2. If yes, please have a look at current code block
3. Do I need to replace properties files by yml files?
public class SIIRunner {
public static void main(String[] args){
String envStr = null;
if (args != null && args.length > 0) {
envStr = args[0];
}
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
SIIExecutor siiExecutor= (SIIExecutor) ctx.getBean("SIIExecutor");
siiExecutor.pollAndOperate();
}
}发布于 2019-08-21 09:40:15
@SpringBootApplication
public class Application {
public static void main(String[] args) throws Exception {
ApplicationContext app = SpringApplication.run(Application.class,
args);//init the context
SIIExecutor siiExecutor = (SIIExecutor)
app.getBean(SIIExecutor.class);//get the bean by type
}
@Bean // this method is the equivalent of the <bean/> tag in xml
public SIIExecutor getBean(){
return new SIIExecutor();
}
}只要您开始使用@Configuration基类(听起来可能像使用@SpringBootApplication ),就可以使用@ImportResource注释来包含XML文件。
@SpringBootApplication
@ImportResource("classpath:beanFileName.xml")
public class SpringConfiguration {
//
}Spring引导的理想概念是避免xml文件。但是,如果您想保留xml,只需添加@ImportResource("classPath:beanFileName.xml")即可。
我建议删除beanFileName.xml文件。并将此文件转换为基于spring注释的bean。因此,任何类都是作为bean创建的。只需在类名之前编写@Service或@Component注释即可。例如:
基于XML的:
<bean ID="id name" class="com.example.MyBean">基于注释的:
@Service or @Component
class MyBean {
}再加上@ComponentScan("Give the package name")。
这是最好的办法。希望这能有所帮助。
https://stackoverflow.com/questions/57587804
复制相似问题