I have a working spring application. Beans are defined in applicationContext.xml.
applicationContext.xml
<bean name="reportFileA" class="com.xyz.ReportFile"> <property name="resource" value="classpath:documents/report01.rptdesign" /> </bean> reportFile class
public class ReportFile { private File file; public void setResource(Resource resource) throws IOException { this.file = resource.getFile(); } public File getFile() { return file; } public String getPath() { return file.getPath(); } } usage in a java class
@Resource(name = "reportFileA") @Required public void setReportFile(ReportFile reportFile) { this.reportFile = reportFile; } This works fine. But now i want to get ride of the bean declartion in xml. How can i make this only with annotations?
The ReportFile class is imported from another own Spring Project.
I am trying to migrate my spring application to spring boot. And i want no more xml configuration.
Possible Solution:
@Bean(name="reportFileA") public ReportFile getReportFile() { ReportFile report = new ReportFile(); try { report.setResource(null); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return report; }
@Beanin your@ConfigurationClass@Component("reportFileA")to the class declaration. Don't know about the property though.