Modernize the integration section of the refdoc
This commit adds Java and Kotlin tabs to XML code snippets where relevant, and leverages code includes. Closes gh-32600
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.cache.cacheannotationenable;
|
||||
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.cache.caffeine.CaffeineCacheManager;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
// tag::snippet[]
|
||||
@Configuration
|
||||
@EnableCaching
|
||||
public class CacheConfiguration {
|
||||
|
||||
@Bean
|
||||
CacheManager cacheManager() {
|
||||
CaffeineCacheManager cacheManager = new CaffeineCacheManager();
|
||||
cacheManager.setCacheSpecification("...");
|
||||
return cacheManager;
|
||||
}
|
||||
}
|
||||
// end::snippet[]
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.cache.cachestoreconfigurationcaffeine;
|
||||
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.caffeine.CaffeineCacheManager;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class CacheConfiguration {
|
||||
|
||||
// tag::snippet[]
|
||||
@Bean
|
||||
CacheManager cacheManager() {
|
||||
return new CaffeineCacheManager();
|
||||
}
|
||||
// end::snippet[]
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.cache.cachestoreconfigurationcaffeine;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.caffeine.CaffeineCacheManager;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class CustomCacheConfiguration {
|
||||
|
||||
// tag::snippet[]
|
||||
@Bean
|
||||
CacheManager cacheManager() {
|
||||
CaffeineCacheManager cacheManager = new CaffeineCacheManager();
|
||||
cacheManager.setCacheNames(List.of("default", "books"));
|
||||
return cacheManager;
|
||||
}
|
||||
// end::snippet[]
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.cache.cachestoreconfigurationjdk;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.concurrent.ConcurrentMapCache;
|
||||
import org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean;
|
||||
import org.springframework.cache.support.SimpleCacheManager;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class CacheConfiguration {
|
||||
|
||||
// tag::snippet[]
|
||||
@Bean
|
||||
ConcurrentMapCacheFactoryBean defaultCache() {
|
||||
ConcurrentMapCacheFactoryBean cache = new ConcurrentMapCacheFactoryBean();
|
||||
cache.setName("default");
|
||||
return cache;
|
||||
}
|
||||
|
||||
@Bean
|
||||
ConcurrentMapCacheFactoryBean booksCache() {
|
||||
ConcurrentMapCacheFactoryBean cache = new ConcurrentMapCacheFactoryBean();
|
||||
cache.setName("books");
|
||||
return cache;
|
||||
}
|
||||
|
||||
@Bean
|
||||
CacheManager cacheManager(ConcurrentMapCache defaultCache, ConcurrentMapCache booksCache) {
|
||||
|
||||
SimpleCacheManager cacheManager = new SimpleCacheManager();
|
||||
cacheManager.setCaches(Set.of(defaultCache, booksCache));
|
||||
return cacheManager;
|
||||
}
|
||||
// end::snippet[]
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.cache.cachestoreconfigurationjsr107;
|
||||
|
||||
import javax.cache.Caching;
|
||||
import javax.cache.spi.CachingProvider;
|
||||
|
||||
import org.springframework.cache.jcache.JCacheCacheManager;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class CacheConfiguration {
|
||||
|
||||
// tag::snippet[]
|
||||
@Bean
|
||||
javax.cache.CacheManager jCacheManager() {
|
||||
CachingProvider cachingProvider = Caching.getCachingProvider();
|
||||
return cachingProvider.getCacheManager();
|
||||
}
|
||||
|
||||
@Bean
|
||||
org.springframework.cache.CacheManager cacheManager(javax.cache.CacheManager jCacheManager) {
|
||||
return new JCacheCacheManager(jCacheManager);
|
||||
}
|
||||
// end::snippet[]
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.cache.cachestoreconfigurationnoop;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.support.CompositeCacheManager;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class CacheConfiguration {
|
||||
|
||||
private CacheManager jdkCache() {
|
||||
return null;
|
||||
}
|
||||
|
||||
private CacheManager gemfireCache() {
|
||||
return null;
|
||||
}
|
||||
|
||||
// tag::snippet[]
|
||||
@Bean
|
||||
CacheManager cacheManager(CacheManager jdkCache, CacheManager gemfireCache) {
|
||||
CompositeCacheManager cacheManager = new CompositeCacheManager();
|
||||
cacheManager.setCacheManagers(List.of(jdkCache, gemfireCache));
|
||||
cacheManager.setFallbackToNoOpCache(true);
|
||||
return cacheManager;
|
||||
}
|
||||
// end::snippet[]
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.jms.jmsannotatedsupport;
|
||||
|
||||
|
||||
import jakarta.jms.ConnectionFactory;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.jms.annotation.EnableJms;
|
||||
import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
|
||||
import org.springframework.jms.support.destination.DestinationResolver;
|
||||
|
||||
// tag::snippet[]
|
||||
@Configuration
|
||||
@EnableJms
|
||||
public class JmsConfiguration {
|
||||
|
||||
@Bean
|
||||
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory(ConnectionFactory connectionFactory,
|
||||
DestinationResolver destinationResolver) {
|
||||
|
||||
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
|
||||
factory.setConnectionFactory(connectionFactory);
|
||||
factory.setDestinationResolver(destinationResolver);
|
||||
factory.setSessionTransacted(true);
|
||||
factory.setConcurrency("3-10");
|
||||
return factory;
|
||||
}
|
||||
}
|
||||
// end::snippet[]
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.jms.jmsjcamessageendpointmanager;
|
||||
|
||||
import jakarta.jms.MessageListener;
|
||||
import jakarta.resource.spi.ResourceAdapter;
|
||||
import org.apache.activemq.ra.ActiveMQActivationSpec;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.jms.listener.endpoint.JmsMessageEndpointManager;
|
||||
|
||||
@Configuration
|
||||
public class AlternativeJmsConfiguration {
|
||||
|
||||
// tag::snippet[]
|
||||
@Bean
|
||||
JmsMessageEndpointManager jmsMessageEndpointManager(ResourceAdapter resourceAdapter,
|
||||
MessageListener myMessageListener) {
|
||||
|
||||
ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
|
||||
spec.setDestination("myQueue");
|
||||
spec.setDestinationType("jakarta.jms.Queue");
|
||||
|
||||
JmsMessageEndpointManager endpointManager = new JmsMessageEndpointManager();
|
||||
endpointManager.setResourceAdapter(resourceAdapter);
|
||||
endpointManager.setActivationSpec(spec);
|
||||
endpointManager.setMessageListener(myMessageListener);
|
||||
return endpointManager;
|
||||
}
|
||||
// end::snippet[]
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.jms.jmsjcamessageendpointmanager;
|
||||
|
||||
|
||||
import jakarta.jms.MessageListener;
|
||||
import jakarta.resource.spi.ResourceAdapter;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.jms.listener.endpoint.JmsActivationSpecConfig;
|
||||
import org.springframework.jms.listener.endpoint.JmsMessageEndpointManager;
|
||||
|
||||
@Configuration
|
||||
public class JmsConfiguration {
|
||||
|
||||
// tag::snippet[]
|
||||
@Bean
|
||||
public JmsMessageEndpointManager jmsMessageEndpointManager(ResourceAdapter resourceAdapter,
|
||||
MessageListener myMessageListener) {
|
||||
|
||||
JmsActivationSpecConfig specConfig = new JmsActivationSpecConfig();
|
||||
specConfig.setDestinationName("myQueue");
|
||||
|
||||
JmsMessageEndpointManager endpointManager = new JmsMessageEndpointManager();
|
||||
endpointManager.setResourceAdapter(resourceAdapter);
|
||||
endpointManager.setActivationSpecConfig(specConfig);
|
||||
endpointManager.setMessageListener(myMessageListener);
|
||||
return endpointManager;
|
||||
}
|
||||
// end::snippet[]
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.jms.jmsreceivingasync;
|
||||
|
||||
import jakarta.jms.JMSException;
|
||||
import jakarta.jms.Message;
|
||||
import jakarta.jms.MessageListener;
|
||||
import jakarta.jms.TextMessage;
|
||||
|
||||
// tag::snippet[]
|
||||
public class ExampleListener implements MessageListener {
|
||||
|
||||
public void onMessage(Message message) {
|
||||
if (message instanceof TextMessage textMessage) {
|
||||
try {
|
||||
System.out.println(textMessage.getText());
|
||||
}
|
||||
catch (JMSException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Message must be of type TextMessage");
|
||||
}
|
||||
}
|
||||
}
|
||||
// end::snippet[]
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.jms.jmsreceivingasync;
|
||||
|
||||
import jakarta.jms.ConnectionFactory;
|
||||
import jakarta.jms.Destination;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.jms.listener.DefaultMessageListenerContainer;
|
||||
|
||||
@Configuration
|
||||
public class JmsConfiguration {
|
||||
|
||||
// tag::snippet[]
|
||||
@Bean
|
||||
ExampleListener messageListener() {
|
||||
return new ExampleListener();
|
||||
}
|
||||
|
||||
@Bean
|
||||
DefaultMessageListenerContainer jmsContainer(ConnectionFactory connectionFactory, Destination destination,
|
||||
ExampleListener messageListener) {
|
||||
|
||||
DefaultMessageListenerContainer jmsContainer = new DefaultMessageListenerContainer();
|
||||
jmsContainer.setConnectionFactory(connectionFactory);
|
||||
jmsContainer.setDestination(destination);
|
||||
jmsContainer.setMessageListener(messageListener);
|
||||
return jmsContainer;
|
||||
}
|
||||
// end::snippet[]
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.jms.jmsreceivingasyncmessagelisteneradapter;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
// tag::snippet[]
|
||||
public class DefaultMessageDelegate implements MessageDelegate {
|
||||
|
||||
@Override
|
||||
public void handleMessage(String message) {
|
||||
// ...
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(Map message) {
|
||||
// ...
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(byte[] message) {
|
||||
// ...
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(Serializable message) {
|
||||
// ...
|
||||
}
|
||||
}
|
||||
// end::snippet[]
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.jms.jmsreceivingasyncmessagelisteneradapter;
|
||||
|
||||
import jakarta.jms.TextMessage;
|
||||
|
||||
// tag::snippet[]
|
||||
public class DefaultResponsiveTextMessageDelegate implements ResponsiveTextMessageDelegate {
|
||||
|
||||
@Override
|
||||
public String receive(TextMessage message) {
|
||||
return "message";
|
||||
}
|
||||
}
|
||||
// end::snippet[]
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.jms.jmsreceivingasyncmessagelisteneradapter;
|
||||
|
||||
import org.springframework.web.socket.TextMessage;
|
||||
|
||||
// tag::snippet[]
|
||||
public class DefaultTextMessageDelegate implements TextMessageDelegate {
|
||||
|
||||
@Override
|
||||
public void receive(TextMessage message) {
|
||||
// ...
|
||||
}
|
||||
}
|
||||
// end::snippet[]
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.jms.jmsreceivingasyncmessagelisteneradapter;
|
||||
|
||||
import jakarta.jms.ConnectionFactory;
|
||||
import jakarta.jms.Destination;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.docs.integration.jms.jmsreceivingasync.ExampleListener;
|
||||
import org.springframework.jms.listener.DefaultMessageListenerContainer;
|
||||
import org.springframework.jms.listener.adapter.MessageListenerAdapter;
|
||||
|
||||
@Configuration
|
||||
public class JmsConfiguration {
|
||||
|
||||
// tag::snippet[]
|
||||
@Bean
|
||||
MessageListenerAdapter messageListener(DefaultMessageDelegate messageDelegate) {
|
||||
return new MessageListenerAdapter(messageDelegate);
|
||||
}
|
||||
|
||||
@Bean
|
||||
DefaultMessageListenerContainer jmsContainer(ConnectionFactory connectionFactory, Destination destination,
|
||||
ExampleListener messageListener) {
|
||||
|
||||
DefaultMessageListenerContainer jmsContainer = new DefaultMessageListenerContainer();
|
||||
jmsContainer.setConnectionFactory(connectionFactory);
|
||||
jmsContainer.setDestination(destination);
|
||||
jmsContainer.setMessageListener(messageListener);
|
||||
return jmsContainer;
|
||||
}
|
||||
// end::snippet[]
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.jms.jmsreceivingasyncmessagelisteneradapter;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
// tag::snippet[]
|
||||
public interface MessageDelegate {
|
||||
|
||||
void handleMessage(String message);
|
||||
|
||||
void handleMessage(Map message);
|
||||
|
||||
void handleMessage(byte[] message);
|
||||
|
||||
void handleMessage(Serializable message);
|
||||
}
|
||||
// end::snippet[]
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.jms.jmsreceivingasyncmessagelisteneradapter;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.jms.listener.adapter.MessageListenerAdapter;
|
||||
|
||||
@Configuration
|
||||
public class MessageListenerConfiguration {
|
||||
|
||||
// tag::snippet[]
|
||||
@Bean
|
||||
MessageListenerAdapter messageListener(DefaultTextMessageDelegate messageDelegate) {
|
||||
MessageListenerAdapter messageListener = new MessageListenerAdapter(messageDelegate);
|
||||
messageListener.setDefaultListenerMethod("receive");
|
||||
// We don't want automatic message context extraction
|
||||
messageListener.setMessageConverter(null);
|
||||
return messageListener;
|
||||
}
|
||||
// end::snippet[]
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.jms.jmsreceivingasyncmessagelisteneradapter;
|
||||
|
||||
import jakarta.jms.TextMessage;
|
||||
|
||||
// tag::snippet[]
|
||||
public interface ResponsiveTextMessageDelegate {
|
||||
|
||||
// Notice the return type...
|
||||
String receive(TextMessage message);
|
||||
}
|
||||
// end::snippet[]
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.jms.jmsreceivingasyncmessagelisteneradapter;
|
||||
|
||||
import org.springframework.web.socket.TextMessage;
|
||||
|
||||
// tag::snippet[]
|
||||
public interface TextMessageDelegate {
|
||||
|
||||
void receive(TextMessage message);
|
||||
}
|
||||
// end::snippet[]
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.jms.jmstxparticipation;
|
||||
|
||||
import jakarta.jms.ConnectionFactory;
|
||||
import jakarta.jms.Destination;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.docs.integration.jms.jmsreceivingasync.ExampleListener;
|
||||
import org.springframework.jms.listener.DefaultMessageListenerContainer;
|
||||
import org.springframework.transaction.jta.JtaTransactionManager;
|
||||
|
||||
@Configuration
|
||||
public class ExternalTxJmsConfiguration {
|
||||
|
||||
// tag::transactionManagerSnippet[]
|
||||
@Bean
|
||||
JtaTransactionManager transactionManager() {
|
||||
return new JtaTransactionManager();
|
||||
}
|
||||
// end::transactionManagerSnippet[]
|
||||
|
||||
// tag::jmsContainerSnippet[]
|
||||
@Bean
|
||||
DefaultMessageListenerContainer jmsContainer(ConnectionFactory connectionFactory, Destination destination,
|
||||
ExampleListener messageListener) {
|
||||
|
||||
DefaultMessageListenerContainer jmsContainer = new DefaultMessageListenerContainer();
|
||||
jmsContainer.setConnectionFactory(connectionFactory);
|
||||
jmsContainer.setDestination(destination);
|
||||
jmsContainer.setMessageListener(messageListener);
|
||||
jmsContainer.setSessionTransacted(true);
|
||||
return jmsContainer;
|
||||
}
|
||||
// end::jmsContainerSnippet[]
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.jms.jmstxparticipation;
|
||||
|
||||
import jakarta.jms.ConnectionFactory;
|
||||
import jakarta.jms.Destination;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.docs.integration.jms.jmsreceivingasync.ExampleListener;
|
||||
import org.springframework.jms.listener.DefaultMessageListenerContainer;
|
||||
|
||||
@Configuration
|
||||
public class JmsConfiguration {
|
||||
|
||||
// tag::snippet[]
|
||||
@Bean
|
||||
DefaultMessageListenerContainer jmsContainer(ConnectionFactory connectionFactory, Destination destination,
|
||||
ExampleListener messageListener) {
|
||||
|
||||
DefaultMessageListenerContainer jmsContainer = new DefaultMessageListenerContainer();
|
||||
jmsContainer.setConnectionFactory(connectionFactory);
|
||||
jmsContainer.setDestination(destination);
|
||||
jmsContainer.setMessageListener(messageListener);
|
||||
jmsContainer.setSessionTransacted(true);
|
||||
return jmsContainer;
|
||||
}
|
||||
// end::snippet[]
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.jmx.jmxcontextmbeanexport;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.EnableMBeanExport;
|
||||
|
||||
// tag::snippet[]
|
||||
@Configuration
|
||||
@EnableMBeanExport(server="myMBeanServer", defaultDomain="myDomain")
|
||||
public class CustomJmxConfiguration {
|
||||
}
|
||||
// end::snippet[]
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.jmx.jmxcontextmbeanexport;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.EnableMBeanExport;
|
||||
|
||||
// tag::snippet[]
|
||||
@Configuration
|
||||
@EnableMBeanExport
|
||||
public class JmxConfiguration {
|
||||
}
|
||||
// end::snippet[]
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.jmx.jmxexporting;
|
||||
|
||||
public interface IJmxTestBean {
|
||||
|
||||
int getAge();
|
||||
|
||||
void setAge(int age);
|
||||
|
||||
void setName(String name);
|
||||
|
||||
String getName();
|
||||
|
||||
int add(int x, int y);
|
||||
|
||||
void dontExposeMe();
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.jmx.jmxexporting;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.jmx.export.MBeanExporter;
|
||||
|
||||
// tag::snippet[]
|
||||
@Configuration
|
||||
public class JmxConfiguration {
|
||||
|
||||
@Bean
|
||||
MBeanExporter exporter(JmxTestBean testBean) {
|
||||
MBeanExporter exporter = new MBeanExporter();
|
||||
exporter.setBeans(Map.of("bean:name=testBean1", testBean));
|
||||
return exporter;
|
||||
}
|
||||
|
||||
@Bean
|
||||
JmxTestBean testBean() {
|
||||
JmxTestBean testBean = new JmxTestBean();
|
||||
testBean.setName("TEST");
|
||||
testBean.setAge(100);
|
||||
return testBean;
|
||||
}
|
||||
}
|
||||
// end::snippet[]
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.jmx.jmxexporting;
|
||||
|
||||
// tag::snippet[]
|
||||
public class JmxTestBean implements IJmxTestBean {
|
||||
|
||||
private String name;
|
||||
private int age;
|
||||
|
||||
@Override
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int add(int x, int y) {
|
||||
return x + y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dontExposeMe() {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
// end::snippet[]
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.mailusage;
|
||||
|
||||
import org.springframework.docs.integration.mailusagesimple.Order;
|
||||
|
||||
// tag::snippet[]
|
||||
public interface OrderManager {
|
||||
|
||||
void placeOrder(Order order);
|
||||
}
|
||||
// end::snippet[]
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.mailusagesimple;
|
||||
|
||||
public class Customer {
|
||||
|
||||
public String getEmailAddress() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.mailusagesimple;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.mail.SimpleMailMessage;
|
||||
import org.springframework.mail.javamail.JavaMailSender;
|
||||
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
||||
|
||||
@Configuration
|
||||
public class MailConfiguration {
|
||||
|
||||
// tag::snippet[]
|
||||
@Bean
|
||||
JavaMailSender mailSender() {
|
||||
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
|
||||
mailSender.setHost("mail.mycompany.example");
|
||||
return mailSender;
|
||||
}
|
||||
|
||||
@Bean // this is a template message that we can pre-load with default state
|
||||
SimpleMailMessage templateMessage() {
|
||||
SimpleMailMessage message = new SimpleMailMessage();
|
||||
message.setFrom("customerservice@mycompany.example");
|
||||
message.setSubject("Your order");
|
||||
return message;
|
||||
}
|
||||
|
||||
@Bean
|
||||
SimpleOrderManager orderManager(JavaMailSender mailSender, SimpleMailMessage templateMessage) {
|
||||
SimpleOrderManager orderManager = new SimpleOrderManager();
|
||||
orderManager.setMailSender(mailSender);
|
||||
orderManager.setTemplateMessage(templateMessage);
|
||||
return orderManager;
|
||||
}
|
||||
// end::snippet[]
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.mailusagesimple;
|
||||
|
||||
public class Order {
|
||||
|
||||
public Customer getCustomer() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getOrderNumber() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.mailusagesimple;
|
||||
|
||||
import org.springframework.docs.integration.mailusage.OrderManager;
|
||||
import org.springframework.mail.SimpleMailMessage;
|
||||
|
||||
import org.springframework.mail.MailException;
|
||||
import org.springframework.mail.MailSender;
|
||||
|
||||
// tag::snippet[]
|
||||
public class SimpleOrderManager implements OrderManager {
|
||||
|
||||
private MailSender mailSender;
|
||||
private SimpleMailMessage templateMessage;
|
||||
|
||||
public void setMailSender(MailSender mailSender) {
|
||||
this.mailSender = mailSender;
|
||||
}
|
||||
|
||||
public void setTemplateMessage(SimpleMailMessage templateMessage) {
|
||||
this.templateMessage = templateMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void placeOrder(Order order) {
|
||||
|
||||
// Do the business calculations...
|
||||
|
||||
// Call the collaborators to persist the order...
|
||||
|
||||
// Create a thread-safe "copy" of the template message and customize it
|
||||
SimpleMailMessage msg = new SimpleMailMessage(this.templateMessage);
|
||||
msg.setTo(order.getCustomer().getEmailAddress());
|
||||
msg.setText(
|
||||
"Dear " + order.getCustomer().getFirstName()
|
||||
+ order.getCustomer().getLastName()
|
||||
+ ", thank you for placing order. Your order number is "
|
||||
+ order.getOrderNumber());
|
||||
try {
|
||||
this.mailSender.send(msg);
|
||||
}
|
||||
catch (MailException ex) {
|
||||
// simply log it and go on...
|
||||
System.err.println(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// end::snippet[]
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.schedulingenableannotationsupport;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
// tag::snippet[]
|
||||
@Configuration
|
||||
@EnableAsync
|
||||
@EnableScheduling
|
||||
public class SchedulingConfiguration {
|
||||
}
|
||||
// end::snippet[]
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.schedulingtaskexecutorusage;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
|
||||
@Configuration
|
||||
public class TaskExecutorConfiguration {
|
||||
|
||||
// tag::snippet[]
|
||||
@Bean
|
||||
ThreadPoolTaskExecutor taskExecutor() {
|
||||
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
|
||||
taskExecutor.setCorePoolSize(5);
|
||||
taskExecutor.setMaxPoolSize(10);
|
||||
taskExecutor.setQueueCapacity(25);
|
||||
return taskExecutor;
|
||||
}
|
||||
|
||||
@Bean
|
||||
TaskExecutorExample taskExecutorExample(ThreadPoolTaskExecutor taskExecutor) {
|
||||
return new TaskExecutorExample(taskExecutor);
|
||||
}
|
||||
// end::snippet[]
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.springframework.docs.integration.schedulingtaskexecutorusage;
|
||||
|
||||
import org.springframework.core.task.TaskExecutor;
|
||||
|
||||
// tag::snippet[]
|
||||
public class TaskExecutorExample {
|
||||
|
||||
private class MessagePrinterTask implements Runnable {
|
||||
|
||||
private String message;
|
||||
|
||||
public MessagePrinterTask(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
System.out.println(message);
|
||||
}
|
||||
}
|
||||
|
||||
private TaskExecutor taskExecutor;
|
||||
|
||||
public TaskExecutorExample(TaskExecutor taskExecutor) {
|
||||
this.taskExecutor = taskExecutor;
|
||||
}
|
||||
|
||||
public void printMessages() {
|
||||
for(int i = 0; i < 25; i++) {
|
||||
taskExecutor.execute(new MessagePrinterTask("Message" + i));
|
||||
}
|
||||
}
|
||||
}
|
||||
// end::snippet[]
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.cache.cacheannotationenable
|
||||
|
||||
import org.springframework.cache.CacheManager
|
||||
import org.springframework.cache.annotation.EnableCaching
|
||||
import org.springframework.cache.caffeine.CaffeineCacheManager
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
|
||||
// tag::snippet[]
|
||||
@Configuration
|
||||
@EnableCaching
|
||||
class CacheConfiguration {
|
||||
|
||||
@Bean
|
||||
fun cacheManager(): CacheManager {
|
||||
return CaffeineCacheManager().apply {
|
||||
setCacheSpecification("...")
|
||||
}
|
||||
}
|
||||
}
|
||||
// end::snippet[]
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.cache.cachestoreconfigurationcaffeine
|
||||
|
||||
import org.springframework.cache.CacheManager
|
||||
import org.springframework.cache.caffeine.CaffeineCacheManager
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
|
||||
|
||||
@Configuration
|
||||
class CacheConfiguration {
|
||||
|
||||
// tag::snippet[]
|
||||
@Bean
|
||||
fun cacheManager(): CacheManager {
|
||||
return CaffeineCacheManager()
|
||||
}
|
||||
// end::snippet[]
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.cache.cachestoreconfigurationcaffeine
|
||||
|
||||
import org.springframework.cache.CacheManager
|
||||
import org.springframework.cache.caffeine.CaffeineCacheManager
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
|
||||
|
||||
@Configuration
|
||||
class CustomCacheConfiguration {
|
||||
|
||||
// tag::snippet[]
|
||||
@Bean
|
||||
fun cacheManager(): CacheManager {
|
||||
return CaffeineCacheManager().apply {
|
||||
cacheNames = listOf("default", "books")
|
||||
}
|
||||
}
|
||||
// end::snippet[]
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.cache.cachestoreconfigurationjdk
|
||||
|
||||
import org.springframework.cache.CacheManager
|
||||
import org.springframework.cache.concurrent.ConcurrentMapCache
|
||||
import org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean
|
||||
import org.springframework.cache.support.SimpleCacheManager
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
|
||||
|
||||
@Configuration
|
||||
class CacheConfiguration {
|
||||
|
||||
// tag::snippet[]
|
||||
@Bean
|
||||
fun defaultCache(): ConcurrentMapCacheFactoryBean {
|
||||
return ConcurrentMapCacheFactoryBean().apply {
|
||||
setName("default")
|
||||
}
|
||||
}
|
||||
|
||||
@Bean
|
||||
fun booksCache(): ConcurrentMapCacheFactoryBean {
|
||||
return ConcurrentMapCacheFactoryBean().apply {
|
||||
setName("books")
|
||||
}
|
||||
}
|
||||
|
||||
@Bean
|
||||
fun cacheManager(defaultCache: ConcurrentMapCache, booksCache: ConcurrentMapCache): CacheManager {
|
||||
return SimpleCacheManager().apply {
|
||||
setCaches(setOf(defaultCache, booksCache))
|
||||
}
|
||||
}
|
||||
// end::snippet[]
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.docs.integration.cache.cachestoreconfigurationjsr107
|
||||
|
||||
import org.springframework.cache.jcache.JCacheCacheManager
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import javax.cache.Caching
|
||||
|
||||
@Suppress("UsePropertyAccessSyntax")
|
||||
@Configuration
|
||||
class CacheConfiguration {
|
||||
|
||||
// tag::snippet[]
|
||||
@Bean
|
||||
fun jCacheManager(): javax.cache.CacheManager {
|
||||
val cachingProvider = Caching.getCachingProvider()
|
||||
return cachingProvider.getCacheManager()
|
||||
}
|
||||
|
||||
@Bean
|
||||
fun cacheManager(jCacheManager: javax.cache.CacheManager): org.springframework.cache.CacheManager {
|
||||
return JCacheCacheManager(jCacheManager)
|
||||
}
|
||||
// end::snippet[]
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.docs.integration.cache.cachestoreconfigurationnoop
|
||||
|
||||
import org.springframework.cache.CacheManager
|
||||
import org.springframework.cache.support.CompositeCacheManager
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
|
||||
@Configuration
|
||||
class CacheConfiguration {
|
||||
|
||||
private fun jdkCache(): CacheManager? {
|
||||
return null
|
||||
}
|
||||
|
||||
private fun gemfireCache(): CacheManager? {
|
||||
return null
|
||||
}
|
||||
|
||||
// tag::snippet[]
|
||||
@Bean
|
||||
fun cacheManager(jdkCache: CacheManager, gemfireCache: CacheManager): CacheManager {
|
||||
return CompositeCacheManager().apply {
|
||||
setCacheManagers(listOf(jdkCache, gemfireCache))
|
||||
setFallbackToNoOpCache(true)
|
||||
}
|
||||
}
|
||||
// end::snippet[]
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.jms.jmsannotatedsupport
|
||||
|
||||
import jakarta.jms.ConnectionFactory
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.jms.annotation.EnableJms
|
||||
import org.springframework.jms.config.DefaultJmsListenerContainerFactory
|
||||
import org.springframework.jms.support.destination.DestinationResolver
|
||||
|
||||
// tag::snippet[]
|
||||
@Configuration
|
||||
@EnableJms
|
||||
class JmsConfiguration {
|
||||
|
||||
@Bean
|
||||
fun jmsListenerContainerFactory(connectionFactory: ConnectionFactory, destinationResolver: DestinationResolver) =
|
||||
DefaultJmsListenerContainerFactory().apply {
|
||||
setConnectionFactory(connectionFactory)
|
||||
setDestinationResolver(destinationResolver)
|
||||
setSessionTransacted(true)
|
||||
setConcurrency("3-10")
|
||||
}
|
||||
}
|
||||
// end::snippet[]
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.jms.jmsjcamessageendpointmanager
|
||||
|
||||
import jakarta.jms.MessageListener
|
||||
import jakarta.resource.spi.ResourceAdapter
|
||||
import org.apache.activemq.ra.ActiveMQActivationSpec
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.jms.listener.endpoint.JmsMessageEndpointManager
|
||||
|
||||
@Configuration
|
||||
class AlternativeJmsConfiguration {
|
||||
|
||||
// tag::snippet[]
|
||||
@Bean
|
||||
fun jmsMessageEndpointManager(
|
||||
resourceAdapter: ResourceAdapter, myMessageListener: MessageListener) = JmsMessageEndpointManager().apply {
|
||||
setResourceAdapter(resourceAdapter)
|
||||
activationSpec = ActiveMQActivationSpec().apply {
|
||||
destination = "myQueue"
|
||||
destinationType = "jakarta.jms.Queue"
|
||||
}
|
||||
messageListener = myMessageListener
|
||||
}
|
||||
// end::snippet[]
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.jms.jmsjcamessageendpointmanager
|
||||
|
||||
import jakarta.jms.MessageListener
|
||||
import jakarta.resource.spi.ResourceAdapter
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.jms.listener.endpoint.JmsActivationSpecConfig
|
||||
import org.springframework.jms.listener.endpoint.JmsMessageEndpointManager
|
||||
|
||||
@Configuration
|
||||
class JmsConfiguration {
|
||||
|
||||
// tag::snippet[]
|
||||
@Bean
|
||||
fun jmsMessageEndpointManager(
|
||||
resourceAdapter: ResourceAdapter, myMessageListener: MessageListener) = JmsMessageEndpointManager().apply {
|
||||
setResourceAdapter(resourceAdapter)
|
||||
activationSpecConfig = JmsActivationSpecConfig().apply {
|
||||
destinationName = "myQueue"
|
||||
}
|
||||
messageListener = myMessageListener
|
||||
}
|
||||
// end::snippet[]
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.jms.jmsreceivingasync
|
||||
|
||||
import jakarta.jms.JMSException
|
||||
import jakarta.jms.Message
|
||||
import jakarta.jms.MessageListener
|
||||
import jakarta.jms.TextMessage
|
||||
|
||||
// tag::snippet[]
|
||||
class ExampleListener : MessageListener {
|
||||
|
||||
override fun onMessage(message: Message) {
|
||||
if (message is TextMessage) {
|
||||
try {
|
||||
println(message.text)
|
||||
} catch (ex: JMSException) {
|
||||
throw RuntimeException(ex)
|
||||
}
|
||||
} else {
|
||||
throw IllegalArgumentException("Message must be of type TextMessage")
|
||||
}
|
||||
}
|
||||
}
|
||||
// end::snippet[]
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.jms.jmsreceivingasync
|
||||
|
||||
import jakarta.jms.ConnectionFactory
|
||||
import jakarta.jms.Destination
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.jms.listener.DefaultMessageListenerContainer
|
||||
|
||||
@Configuration
|
||||
class JmsConfiguration {
|
||||
|
||||
// tag::snippet[]
|
||||
@Bean
|
||||
fun messageListener() = ExampleListener()
|
||||
|
||||
@Bean
|
||||
fun jmsContainer(connectionFactory: ConnectionFactory, destination: Destination, messageListener: ExampleListener) =
|
||||
DefaultMessageListenerContainer().apply {
|
||||
setConnectionFactory(connectionFactory)
|
||||
setDestination(destination)
|
||||
setMessageListener(messageListener)
|
||||
}
|
||||
// end::snippet[]
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.jms.jmsreceivingasyncmessagelisteneradapter
|
||||
|
||||
import java.io.Serializable
|
||||
|
||||
// tag::snippet[]
|
||||
class DefaultMessageDelegate : MessageDelegate {
|
||||
|
||||
override fun handleMessage(message: String) {
|
||||
// ...
|
||||
}
|
||||
|
||||
override fun handleMessage(message: Map<*, *>) {
|
||||
// ...
|
||||
}
|
||||
|
||||
override fun handleMessage(message: ByteArray) {
|
||||
// ...
|
||||
}
|
||||
|
||||
override fun handleMessage(message: Serializable) {
|
||||
// ...
|
||||
}
|
||||
}
|
||||
// end::snippet[]
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.jms.jmsreceivingasyncmessagelisteneradapter
|
||||
|
||||
import jakarta.jms.TextMessage
|
||||
|
||||
// tag::snippet[]
|
||||
class DefaultResponsiveTextMessageDelegate : ResponsiveTextMessageDelegate {
|
||||
|
||||
override fun receive(message: TextMessage): String {
|
||||
return "message"
|
||||
}
|
||||
}
|
||||
// end::snippet[]
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.jms.jmsreceivingasyncmessagelisteneradapter
|
||||
|
||||
import org.springframework.web.socket.TextMessage
|
||||
|
||||
// tag::snippet[]
|
||||
class DefaultTextMessageDelegate : TextMessageDelegate {
|
||||
|
||||
override fun receive(message: TextMessage) {
|
||||
// ...
|
||||
}
|
||||
}
|
||||
// end::snippet[]
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.jms.jmsreceivingasyncmessagelisteneradapter
|
||||
|
||||
import jakarta.jms.ConnectionFactory
|
||||
import jakarta.jms.Destination
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.docs.integration.jms.jmsreceivingasync.ExampleListener
|
||||
import org.springframework.jms.listener.DefaultMessageListenerContainer
|
||||
import org.springframework.jms.listener.adapter.MessageListenerAdapter
|
||||
|
||||
@Configuration
|
||||
class JmsConfiguration {
|
||||
|
||||
// tag::snippet[]
|
||||
@Bean
|
||||
fun messageListener(messageDelegate: DefaultMessageDelegate): MessageListenerAdapter {
|
||||
return MessageListenerAdapter(messageDelegate)
|
||||
}
|
||||
|
||||
@Bean
|
||||
fun jmsContainer(connectionFactory: ConnectionFactory, destination: Destination, messageListener: ExampleListener) =
|
||||
DefaultMessageListenerContainer().apply {
|
||||
setConnectionFactory(connectionFactory)
|
||||
setDestination(destination)
|
||||
setMessageListener(messageListener)
|
||||
}
|
||||
// end::snippet[]
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.jms.jmsreceivingasyncmessagelisteneradapter
|
||||
|
||||
import java.io.Serializable
|
||||
|
||||
// tag::snippet[]
|
||||
interface MessageDelegate {
|
||||
fun handleMessage(message: String)
|
||||
fun handleMessage(message: Map<*, *>)
|
||||
fun handleMessage(message: ByteArray)
|
||||
fun handleMessage(message: Serializable)
|
||||
}
|
||||
// end::snippet[]
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.jms.jmsreceivingasyncmessagelisteneradapter
|
||||
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.jms.listener.adapter.MessageListenerAdapter
|
||||
|
||||
@Configuration
|
||||
class MessageListenerConfiguration {
|
||||
|
||||
// tag::snippet[]
|
||||
@Bean
|
||||
fun messageListener(messageDelegate: DefaultTextMessageDelegate) = MessageListenerAdapter(messageDelegate).apply {
|
||||
setDefaultListenerMethod("receive")
|
||||
// We don't want automatic message context extraction
|
||||
setMessageConverter(null)
|
||||
}
|
||||
// end::snippet[]
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.jms.jmsreceivingasyncmessagelisteneradapter
|
||||
|
||||
import jakarta.jms.TextMessage
|
||||
|
||||
// tag::snippet[]
|
||||
interface ResponsiveTextMessageDelegate {
|
||||
|
||||
// Notice the return type...
|
||||
fun receive(message: TextMessage): String
|
||||
}
|
||||
// end::snippet[]
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.jms.jmsreceivingasyncmessagelisteneradapter
|
||||
|
||||
import org.springframework.web.socket.TextMessage
|
||||
|
||||
// tag::snippet[]
|
||||
interface TextMessageDelegate {
|
||||
fun receive(message: TextMessage)
|
||||
}
|
||||
// end::snippet[]
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.jms.jmstxparticipation
|
||||
|
||||
import jakarta.jms.ConnectionFactory
|
||||
import jakarta.jms.Destination
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.docs.integration.jms.jmsreceivingasync.ExampleListener
|
||||
import org.springframework.jms.listener.DefaultMessageListenerContainer
|
||||
import org.springframework.transaction.jta.JtaTransactionManager
|
||||
|
||||
@Configuration
|
||||
class ExternalTxJmsConfiguration {
|
||||
|
||||
// tag::transactionManagerSnippet[]
|
||||
@Bean
|
||||
fun transactionManager() = JtaTransactionManager()
|
||||
// end::transactionManagerSnippet[]
|
||||
|
||||
// tag::jmsContainerSnippet[]
|
||||
@Bean
|
||||
fun jmsContainer(connectionFactory: ConnectionFactory, destination: Destination, messageListener: ExampleListener,
|
||||
transactionManager: JtaTransactionManager) =
|
||||
DefaultMessageListenerContainer().apply {
|
||||
setConnectionFactory(connectionFactory)
|
||||
setDestination(destination)
|
||||
setMessageListener(messageListener)
|
||||
setTransactionManager(transactionManager)
|
||||
}
|
||||
// end::jmsContainerSnippet[]
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.jms.jmstxparticipation
|
||||
|
||||
import jakarta.jms.ConnectionFactory
|
||||
import jakarta.jms.Destination
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.docs.integration.jms.jmsreceivingasync.ExampleListener
|
||||
import org.springframework.jms.listener.DefaultMessageListenerContainer
|
||||
|
||||
@Configuration
|
||||
class JmsConfiguration {
|
||||
|
||||
// tag::snippet[]
|
||||
@Bean
|
||||
fun jmsContainer(connectionFactory: ConnectionFactory, destination: Destination, messageListener: ExampleListener) =
|
||||
DefaultMessageListenerContainer().apply {
|
||||
setConnectionFactory(connectionFactory)
|
||||
setDestination(destination)
|
||||
setMessageListener(messageListener)
|
||||
isSessionTransacted = true
|
||||
}
|
||||
// end::snippet[]
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.jmx.jmxcontextmbeanexport
|
||||
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.context.annotation.EnableMBeanExport
|
||||
|
||||
// tag::snippet[]
|
||||
@Configuration
|
||||
@EnableMBeanExport(server="myMBeanServer", defaultDomain="myDomain")
|
||||
class CustomJmxConfiguration
|
||||
// end::snippet[]
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.jmx.jmxcontextmbeanexport
|
||||
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.context.annotation.EnableMBeanExport
|
||||
|
||||
// tag::snippet[]
|
||||
@Configuration
|
||||
@EnableMBeanExport
|
||||
class JmxConfiguration
|
||||
// end::snippet[]
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.jmx.jmxexporting
|
||||
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.jmx.export.MBeanExporter
|
||||
|
||||
// tag::snippet[]
|
||||
@Configuration
|
||||
class JmxConfiguration {
|
||||
|
||||
@Bean
|
||||
fun exporter(testBean: JmxTestBean) = MBeanExporter().apply {
|
||||
setBeans(mapOf("bean:name=testBean1" to testBean))
|
||||
}
|
||||
|
||||
@Bean
|
||||
fun testBean() = JmxTestBean().apply {
|
||||
name = "TEST"
|
||||
age = 100
|
||||
}
|
||||
}
|
||||
// end::snippet[]
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.jmx.jmxexporting
|
||||
|
||||
// tag::snippet[]
|
||||
class JmxTestBean : IJmxTestBean {
|
||||
|
||||
private lateinit var name: String
|
||||
private var age = 0
|
||||
|
||||
override fun getAge(): Int {
|
||||
return age
|
||||
}
|
||||
|
||||
override fun setAge(age: Int) {
|
||||
this.age = age
|
||||
}
|
||||
|
||||
override fun setName(name: String) {
|
||||
this.name = name
|
||||
}
|
||||
|
||||
override fun getName(): String {
|
||||
return name
|
||||
}
|
||||
|
||||
override fun add(x: Int, y: Int): Int {
|
||||
return x + y
|
||||
}
|
||||
|
||||
override fun dontExposeMe() {
|
||||
throw RuntimeException()
|
||||
}
|
||||
}
|
||||
// end::snippet[]
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.mailusage
|
||||
|
||||
import org.springframework.docs.integration.mailusagesimple.Order
|
||||
|
||||
// tag::snippet[]
|
||||
interface OrderManager {
|
||||
|
||||
fun placeOrder(order: Order)
|
||||
}
|
||||
// end::snippet[]
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.mailusagesimple
|
||||
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.mail.SimpleMailMessage
|
||||
import org.springframework.mail.javamail.JavaMailSender
|
||||
import org.springframework.mail.javamail.JavaMailSenderImpl
|
||||
|
||||
@Configuration
|
||||
class MailConfiguration {
|
||||
|
||||
// tag::snippet[]
|
||||
@Bean
|
||||
fun mailSender(): JavaMailSender {
|
||||
return JavaMailSenderImpl().apply {
|
||||
host = "mail.mycompany.example"
|
||||
}
|
||||
}
|
||||
|
||||
@Bean // this is a template message that we can pre-load with default state
|
||||
fun templateMessage() = SimpleMailMessage().apply {
|
||||
from = "customerservice@mycompany.example"
|
||||
subject = "Your order"
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
fun orderManager(javaMailSender: JavaMailSender, simpleTemplateMessage: SimpleMailMessage) = SimpleOrderManager().apply {
|
||||
mailSender = javaMailSender
|
||||
templateMessage = simpleTemplateMessage
|
||||
}
|
||||
// end::snippet[]
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.mailusagesimple
|
||||
|
||||
import org.springframework.docs.integration.mailusage.OrderManager
|
||||
import org.springframework.mail.MailException
|
||||
import org.springframework.mail.MailSender
|
||||
import org.springframework.mail.SimpleMailMessage
|
||||
|
||||
// tag::snippet[]
|
||||
class SimpleOrderManager : OrderManager {
|
||||
|
||||
lateinit var mailSender: MailSender
|
||||
lateinit var templateMessage: SimpleMailMessage
|
||||
|
||||
override fun placeOrder(order: Order) {
|
||||
// Do the business calculations...
|
||||
|
||||
// Call the collaborators to persist the order...
|
||||
|
||||
// Create a thread-safe "copy" of the template message and customize it
|
||||
|
||||
val msg = SimpleMailMessage(this.templateMessage)
|
||||
msg.setTo(order.customer.emailAddress)
|
||||
msg.text = ("Dear " + order.customer.firstName
|
||||
+ order.customer.lastName
|
||||
+ ", thank you for placing order. Your order number is "
|
||||
+ order.orderNumber)
|
||||
try {
|
||||
mailSender.send(msg)
|
||||
} catch (ex: MailException) {
|
||||
// simply log it and go on...
|
||||
System.err.println(ex.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
// end::snippet[]
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.schedulingenableannotationsupport
|
||||
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.scheduling.annotation.EnableAsync
|
||||
import org.springframework.scheduling.annotation.EnableScheduling
|
||||
|
||||
// tag::snippet[]
|
||||
@Configuration
|
||||
@EnableAsync
|
||||
@EnableScheduling
|
||||
class SchedulingConfiguration
|
||||
// end::snippet[]
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.schedulingtaskexecutorusage
|
||||
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
|
||||
|
||||
@Configuration
|
||||
class TaskExecutorConfiguration {
|
||||
|
||||
// tag::snippet[]
|
||||
@Bean
|
||||
fun taskExecutor() = ThreadPoolTaskExecutor().apply {
|
||||
corePoolSize = 5
|
||||
maxPoolSize = 10
|
||||
queueCapacity = 25
|
||||
}
|
||||
|
||||
@Bean
|
||||
fun taskExecutorExample(taskExecutor: ThreadPoolTaskExecutor) = TaskExecutorExample(taskExecutor)
|
||||
// end::snippet[]
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.docs.integration.schedulingtaskexecutorusage
|
||||
|
||||
import org.springframework.core.task.TaskExecutor
|
||||
|
||||
// tag::snippet[]
|
||||
class TaskExecutorExample(private val taskExecutor: TaskExecutor) {
|
||||
|
||||
private inner class MessagePrinterTask(private val message: String) : Runnable {
|
||||
override fun run() {
|
||||
println(message)
|
||||
}
|
||||
}
|
||||
|
||||
fun printMessages() {
|
||||
for (i in 0..24) {
|
||||
taskExecutor.execute(
|
||||
MessagePrinterTask(
|
||||
"Message$i"
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
// end::snippet[]
|
||||
@@ -0,0 +1,15 @@
|
||||
<!-- tag::snippet[] -->
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:cache="http://www.springframework.org/schema/cache"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/cache https://www.springframework.org/schema/cache/spring-cache.xsd">
|
||||
|
||||
<cache:annotation-driven/>
|
||||
|
||||
<bean id="cacheManager" class="org.springframework.cache.caffeine.CaffeineCacheManager">
|
||||
<property name="cacheSpecification" value="..."/>
|
||||
</bean>
|
||||
</beans>
|
||||
<!-- end::snippet[] -->
|
||||
@@ -0,0 +1,10 @@
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<!-- tag::snippet[] -->
|
||||
<bean id="cacheManager" class="org.springframework.cache.caffeine.CaffeineCacheManager"/>
|
||||
<!-- end::snippet[] -->
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,17 @@
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<!-- tag::snippet[] -->
|
||||
<bean id="cacheManager" class="org.springframework.cache.caffeine.CaffeineCacheManager">
|
||||
<property name="cacheNames">
|
||||
<set>
|
||||
<value>default</value>
|
||||
<value>books</value>
|
||||
</set>
|
||||
</property>
|
||||
</bean>
|
||||
<!-- end::snippet[] -->
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,18 @@
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<!-- tag::snippet[] -->
|
||||
<!-- simple cache manager -->
|
||||
<bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager">
|
||||
<property name="caches">
|
||||
<set>
|
||||
<bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean" name="default"/>
|
||||
<bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean" name="books"/>
|
||||
</set>
|
||||
</property>
|
||||
</bean>
|
||||
<!-- end::snippet[] -->
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:p="http://www.springframework.org/schema/p"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<!-- tag::snippet[] -->
|
||||
<bean id="cacheManager"
|
||||
class="org.springframework.cache.jcache.JCacheCacheManager"
|
||||
p:cache-manager-ref="jCacheManager"/>
|
||||
|
||||
<!-- JSR-107 cache manager setup -->
|
||||
<bean id="jCacheManager" .../>
|
||||
<!-- end::snippet[] -->
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,19 @@
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:p="http://www.springframework.org/schema/p"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<!-- tag::snippet[] -->
|
||||
<bean id="cacheManager" class="org.springframework.cache.support.CompositeCacheManager">
|
||||
<property name="cacheManagers">
|
||||
<list>
|
||||
<ref bean="jdkCache"/>
|
||||
<ref bean="gemfireCache"/>
|
||||
</list>
|
||||
</property>
|
||||
<property name="fallbackToNoOpCache" value="true"/>
|
||||
</bean>
|
||||
<!-- end::snippet[] -->
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,18 @@
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jms="http://www.springframework.org/schema/jms"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
https://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/jms https://www.springframework.org/schema/jms/spring-jms.xsd">
|
||||
|
||||
<!-- tag::snippet[] -->
|
||||
<jms:annotation-driven/>
|
||||
|
||||
<bean id="jmsListenerContainerFactory" class="org.springframework.jms.config.DefaultJmsListenerContainerFactory">
|
||||
<property name="connectionFactory" ref="connectionFactory"/>
|
||||
<property name="destinationResolver" ref="destinationResolver"/>
|
||||
<property name="sessionTransacted" value="true"/>
|
||||
<property name="concurrency" value="3-10"/>
|
||||
</bean>
|
||||
<!-- end::snippet[] -->
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,19 @@
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
https://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<!-- tag::snippet[] -->
|
||||
<bean class="org.springframework.jms.listener.endpoint.JmsMessageEndpointManager">
|
||||
<property name="resourceAdapter" ref="resourceAdapter"/>
|
||||
<property name="activationSpec">
|
||||
<bean class="org.apache.activemq.ra.ActiveMQActivationSpec">
|
||||
<property name="destination" value="myQueue"/>
|
||||
<property name="destinationType" value="jakarta.jms.Queue"/>
|
||||
</bean>
|
||||
</property>
|
||||
<property name="messageListener" ref="myMessageListener"/>
|
||||
</bean>
|
||||
<!-- end::snippet[] -->
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,18 @@
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
https://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<!-- tag::snippet[] -->
|
||||
<bean class="org.springframework.jms.listener.endpoint.JmsMessageEndpointManager">
|
||||
<property name="resourceAdapter" ref="resourceAdapter"/>
|
||||
<property name="activationSpecConfig">
|
||||
<bean class="org.springframework.jms.listener.endpoint.JmsActivationSpecConfig">
|
||||
<property name="destinationName" value="myQueue"/>
|
||||
</bean>
|
||||
</property>
|
||||
<property name="messageListener" ref="myMessageListener"/>
|
||||
</bean>
|
||||
<!-- end::snippet[] -->
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,18 @@
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
https://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<!-- tag::snippet[] -->
|
||||
<!-- this is the Message Driven POJO (MDP) -->
|
||||
<bean id="messageListener" class="jmsexample.ExampleListener"/>
|
||||
|
||||
<!-- and this is the message listener container -->
|
||||
<bean id="jmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
|
||||
<property name="connectionFactory" ref="connectionFactory"/>
|
||||
<property name="destination" ref="destination"/>
|
||||
<property name="messageListener" ref="messageListener"/>
|
||||
</bean>
|
||||
<!-- end::snippet[] -->
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,22 @@
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
https://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<!-- tag::snippet[] -->
|
||||
<!-- this is the Message Driven POJO (MDP) -->
|
||||
<bean id="messageListener" class="org.springframework.jms.listener.adapter.MessageListenerAdapter">
|
||||
<constructor-arg>
|
||||
<bean class="jmsexample.DefaultMessageDelegate"/>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
<!-- and this is the message listener container... -->
|
||||
<bean id="jmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
|
||||
<property name="connectionFactory" ref="connectionFactory"/>
|
||||
<property name="destination" ref="destination"/>
|
||||
<property name="messageListener" ref="messageListener"/>
|
||||
</bean>
|
||||
<!-- end::snippet[] -->
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,19 @@
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
https://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<!-- tag::snippet[] -->
|
||||
<bean id="messageListener" class="org.springframework.jms.listener.adapter.MessageListenerAdapter">
|
||||
<constructor-arg>
|
||||
<bean class="jmsexample.DefaultTextMessageDelegate"/>
|
||||
</constructor-arg>
|
||||
<property name="defaultListenerMethod" value="receive"/>
|
||||
<!-- we don't want automatic message context extraction -->
|
||||
<property name="messageConverter">
|
||||
<null/>
|
||||
</property>
|
||||
</bean>
|
||||
<!-- end::snippet[] -->
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,20 @@
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jms="http://www.springframework.org/schema/jms"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
https://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/jms https://www.springframework.org/schema/jms/spring-jms.xsd">
|
||||
|
||||
<!-- tag::transactionManagerSnippet[] -->
|
||||
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"/>
|
||||
<!-- end::transactionManagerSnippet[] -->
|
||||
|
||||
<!-- tag::jmsContainerSnippet[] -->
|
||||
<bean id="jmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
|
||||
<property name="connectionFactory" ref="connectionFactory"/>
|
||||
<property name="destination" ref="destination"/>
|
||||
<property name="messageListener" ref="messageListener"/>
|
||||
<property name="transactionManager" ref="transactionManager"/>
|
||||
</bean>
|
||||
<!-- end::jmsContainerSnippet[] -->
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,15 @@
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
https://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<!-- tag::snippet[] -->
|
||||
<bean id="jmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
|
||||
<property name="connectionFactory" ref="connectionFactory"/>
|
||||
<property name="destination" ref="destination"/>
|
||||
<property name="messageListener" ref="messageListener"/>
|
||||
<property name="sessionTransacted" value="true"/>
|
||||
</bean>
|
||||
<!-- end::snippet[] -->
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,12 @@
|
||||
<!-- tag::snippet[] -->
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
https://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
https://www.springframework.org/schema/context/spring-context.xsd">
|
||||
|
||||
<context:mbean-export server="myMBeanServer" default-domain="myDomain"/>
|
||||
</beans>
|
||||
<!-- end::snippet[] -->
|
||||
@@ -0,0 +1,12 @@
|
||||
<!-- tag::snippet[] -->
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
https://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
https://www.springframework.org/schema/context/spring-context.xsd">
|
||||
|
||||
<context:mbean-export/>
|
||||
</beans>
|
||||
<!-- end::snippet[] -->
|
||||
@@ -0,0 +1,21 @@
|
||||
<!-- tag::snippet[] -->
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
https://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<!-- this bean must not be lazily initialized if the exporting is to happen -->
|
||||
<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter">
|
||||
<property name="beans">
|
||||
<map>
|
||||
<entry key="bean:name=testBean1" value-ref="testBean"/>
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="testBean" class="org.example.JmxTestBean">
|
||||
<property name="name" value="TEST"/>
|
||||
<property name="age" value="100"/>
|
||||
</bean>
|
||||
</beans>
|
||||
<!-- end::snippet[] -->
|
||||
@@ -0,0 +1,24 @@
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jms="http://www.springframework.org/schema/jms"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
https://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/jms https://www.springframework.org/schema/jms/spring-jms.xsd">
|
||||
|
||||
<!-- tag::snippet[] -->
|
||||
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
|
||||
<property name="host" value="mail.mycompany.example"/>
|
||||
</bean>
|
||||
|
||||
<!-- this is a template message that we can pre-load with default state -->
|
||||
<bean id="templateMessage" class="org.springframework.mail.SimpleMailMessage">
|
||||
<property name="from" value="customerservice@mycompany.example"/>
|
||||
<property name="subject" value="Your order"/>
|
||||
</bean>
|
||||
|
||||
<bean id="orderManager" class="com.mycompany.businessapp.support.SimpleOrderManager">
|
||||
<property name="mailSender" ref="mailSender"/>
|
||||
<property name="templateMessage" ref="templateMessage"/>
|
||||
</bean>
|
||||
<!-- end::snippet[] -->
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,13 @@
|
||||
<!-- tag::snippet[] -->
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:task="http://www.springframework.org/schema/task"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
https://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/task
|
||||
https://www.springframework.org/schema/task/spring-task.xsd">
|
||||
|
||||
<task:annotation-driven executor="myExecutor" scheduler="myScheduler"/>
|
||||
<task:executor id="myExecutor" pool-size="5"/>
|
||||
<task:scheduler id="myScheduler" pool-size="10"/>
|
||||
</beans>
|
||||
<!-- end::snippet[] -->
|
||||
@@ -0,0 +1,18 @@
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
https://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<!-- tag::snippet[] -->
|
||||
<bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
|
||||
<property name="corePoolSize" value="5"/>
|
||||
<property name="maxPoolSize" value="10"/>
|
||||
<property name="queueCapacity" value="25"/>
|
||||
</bean>
|
||||
|
||||
<bean id="taskExecutorExample" class="TaskExecutorExample">
|
||||
<constructor-arg ref="taskExecutor"/>
|
||||
</bean>
|
||||
<!-- end::snippet[] -->
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user