xml


Where do I put my XML beans in a Spring Boot application?


I'm getting back into Spring (currently v4). It's all wonderful now with #SpringBootApplication and the other annotations but all the documentation seems to forget to mention how I define other beans in XML!
For example I'd like to create an "SFTP Session Factory" as defined at:
http://docs.spring.io/spring-integration/reference/html/sftp.html
There is a nice bit of XML to define the bean but where on earth do I put it and how do I link it in? Previously I did a:
ApplicationContext context = new ClassPathXmlApplicationContext(
"classpath:applicationContext.xml");
to specify the file name and location but now that I'm trying to use:
ApplicationContext ctx = SpringApplication.run(Application.class);
Where do I put the XML file? Is there a magic spring name to call it?
As long as you're starting with a base #Configuration class to begin with, which it maybe sounds like you are with #SpringBootApplication, you can use the #ImportResource annotation to include an XML configuration file as well.
#SpringBootApplication
#ImportResource("classpath:spring-sftp-config.xml")
public class SpringConfiguration {
//
}
You also can translate the XML config to a Java config. In your case it would look like:
#Bean
public DefaultSftpSessionFactory sftpSessionFactory() {
DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory();
factory.setHost("localhost");
factory.setPrivateKey(new ClassPathResource("classpath:META-INF/keys/sftpTest"));
factory.setPrivateKeyPassphrase("springIntegration");
factory.setPort(22);
factory.setUser("kermit");
return factory;
}
You can put this method in the class with the #SpringBootApplication annotation.

Related Links

read RDF/XML from url in Jena
When does XML receive it's value to display?
Add new tag to the XML using Batch script
space between xml tags
XSL - check if attribute is equal to the selected value
VB.Net TableAdapter XSD file has “randomly” stopped working
Convert XML to CSV with XSLT
Obtain value from XML element using XML parser and assign it to a variable
How to parse xml in powershell
How to hide External Header in Odoo reports using XML
How can I parse XML in PowerShell when each property has a unique name?
Adding Nodes to an IXMLNodeCollection in Delphi XE7
How to serialize xml request posted on WebAPI
Select and replace a string from an xml file in all occurences via shell scripting
How to Give action to the print button in odoo 9?
How to get 1st-level comment from root element of xml

Categories

HOME
porting
design-patterns
twig
powerpoint
camera
solver
error-handling
knitr
seo
big-o
nested-if
gluon-mobile
webix
joomla3.0
spin
32bit-64bit
java.util.logging
alamofire
emoji
ycsb
spring-social
heat
do-while
entitymanager
smartclient
charles
user-experience
backpack-for-laravel
qliksense
highstock
jquery-callback
froala
dapper-extensions
fat
flooding
userdefaults
weather
cognos-bi
dumpbin
papaparse
keras-layer
openwhisk
getlasterror
hivemq
alphabetical
playframework-2.1
filesystemwatcher
verifiable-c
css-position
comparison-operators
apache-directory
optimizely
puredata
proget
openblas
magic-draw
azure-cli
appdomain
reshape
py2neo
angular2-testing
seek
hclust
installshield-2010
clipboard.js
google-query-language
terracotta
sapscript
document-repository
iiop
browserify-shim
sip-server
unix-socket
build-script
dot42
fpdi
cfcache
http-patch
mysql-error-1044
windows-phone-8-sdk
hidapi
cascadingdropdown
web-notifications
redis-py
onmousemove
midlet
oracle-enterprise-linux
flex-mobile
ikimagebrowserview
clrstoredprocedure
delimited-text
request-headers
spread
wysiwym
int64

Resources

Encrypt Message