Is there a reason you want to use camel.spring.Main and register the beans/routes yourself? The beans added to the Spring bean registry should be available in the Camel Bean registry. You should be able to use the Component scan for your Routes and also a Configuration Class to define any specific beans to be part of the registry like the CloudBlockBlob client. No Spring XML needed.
Here's an example of using the annotations for Spring/Camel in this manner which you don't need to manually add your routes and beans. I didn't test that the Azure component actually works with this example as i don't have an Azure account at the ready to verify, but I've been using the same pattern in other projects with success. https://github.com/runstache/camel-sample-springdsl On Mon, May 13, 2019 at 6:54 AM Marx, Peter <[email protected]> wrote: > I want to move my use case from standalone JavaDSL to Spring, later to > Docker/k8s, but with a minimum of XML. > > When replacing org.apache.camel.main.Main with > org.apache.camel.spring.Main, adding a bean to registry no longer works: > > import org.apache.camel.spring.Main; > > Main myapp = new Main(); > > myapp.bind("credsreg", new CredsBean().creds()); //add bean to > default camel registry > > ... > > > > static class CredsBean > { > xy creds() > > { > xy creds = new ... ; > return creds; > } > } > > > > (later I look up the bean in a route like this: > ...?credentials=#credsreg ) > > > > > This is because camel.spring.Main has no bind method in contrast to > camel.main.Main. > > What alternatives do I have to get my bean stored in a registry without > using SpringXML, which would mean e.g. > <bean id="credsreg" class="package."/> ? > > Can I use the default ApplicationContextRegistry then? > > Peter > > > From: Marx, Peter > Sent: Friday, April 19, 2019 10:56 AM > To: '[email protected]' <[email protected]> > Subject: azure-blob with JavaDSL: can't set URI options with bean or any > other method > > Hi, > > I want to add a route for the camel-azure component 2.23.0 in pure JavaDSL > with no Spring. Documentation > https://github.com/apache/camel/blob/master/components/camel-azure/src/main/docs/azure-blob-component.adoc > only recommends to set the credentials and client options with a bean, but > I can't get that to work. How to set the options directly in the URI is > not described. > Without bean I get an exception like this: > > [ERROR] Failed to execute goal > org.codehaus.mojo:exec-maven-plugin:1.6.0:java (default-cli) on project > testjava: An exception occured while executing the Java class. Failed to > create route route1: > Route(route1)[[From[azure-blob:/shared1/mxtest/blabla?azureB... because of > Failed to resolve endpoint: > azure-blob:///shared1/mxtest/blabla?azureBlobClient=client due to: Could > not find a suitable setter for property: azureBlobClient as there isn't a > setter method with same type: java.lang.String nor type conversion > possible: No type converter available to convert from type: > java.lang.String to the required type: > com.microsoft.azure.storage.blob.CloudBlob with value client > > With bean it is the same error "no type converter...with value > #clientreg" - I assume the bean lookup does not work - would be my 2. > question how to fix that.. > > The azureBlobClient option must be of type CloudBlockBlob, credentials of > type StorageCredentials. > > How can I set the required credentials or client options in the URI ? > > > Peter > > > package testjava; > > import org.apache.camel.*; > import org.apache.camel.impl.SimpleRegistry; > import org.apache.camel.language.Bean; > import org.apache.camel.main.Main; > import org.apache.camel.CamelContext; > import org.apache.camel.impl.DefaultCamelContext; > import org.apache.camel.builder.RouteBuilder; > import com.microsoft.azure.storage.*; > import com.microsoft.azure.storage.blob.*; > > public class MainApp > { > public static class ClientBean > { > public CloudBlockBlob client() > { > try > { > StorageCredentials creds = > new StorageCredentialsAccountAndKey("shared1", "here gooes my key > jG/zyK...."); > StorageUri storageURI = new > StorageUri(new java.net.URI("https://shared1.blob.core.windows.net/mxtest > ")); > CloudBlockBlob client = new > CloudBlockBlob(storageURI, creds); > return client; > } > catch(Exception e) > { > return null; > } > } > } > > public static void main(String... args) throws Exception > { > SimpleRegistry myregistry = new SimpleRegistry(); > CamelContext mycontext = new > DefaultCamelContext(myregistry); > myregistry.put("clientreg", new ClientBean()); > > // as bean does not work, I try to set the stuff > directly: > StorageCredentials creds = new > StorageCredentialsAccountAndKey("shared1", "here goes my key"); > StorageUri storageURI = new StorageUri(new > java.net.URI("https://shared1.blob.core.windows.net/mxtest")); > CloudBlockBlob client = new > CloudBlockBlob(storageURI, creds); > > mycontext.addRoutes > (new RouteBuilder() > { > @Override > public void > configure() > { > > //bean does not work: > from("azure-blob:/shared1/mxtest/blabla?azureBlobClient=#clientreg") > > from("azure-blob:/shared1/mxtest/blabla?azureBlobClient=client") > > .to("file:c:\\mx\\source"); > } > } > ); > mycontext.start(); > } > } > > > > Knorr-Bremse Systeme für Schienenfahrzeuge GmbH > Sitz: München > Geschäftsführer: Dr. Jürgen Wilder (Vorsitzender), Mark Cleobury, Dr. > Nicolas Lange, Dr. Peter Radina, Harald Schneider > Registergericht München, HR B 91 181 > > This transmission is intended solely for the addressee and contains > confidential information. > If you are not the intended recipient, please immediately inform the > sender and delete the message and any attachments from your system. > Furthermore, please do not copy the message or disclose the contents to > anyone unless agreed otherwise. To the extent permitted by law we shall in > no way be liable for any damages, whatever their nature, arising out of > transmission failures, viruses, external influence, delays and the like. > >
