This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<filter> | |
<filter-name>SpringSparkFilter</filter-name> | |
<filter-class>com.zhentao.sparkjava.example.SpringSparkFilter</filter-class> | |
<init-param> | |
<param-name>applicationClass</param-name> | |
<param-value>com.zhentao.sparkjava.example.MySparkApplication</param-value> | |
</init-param> | |
<init-param> | |
<!-- Configuration locations must consist of one or more comma-delimited fully-qualified @Configuration classes --> | |
<param-name>springConfigLocation</param-name> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void init() { | |
get("/my-resource", (req, res) -> { | |
return exampleService.getDate(); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
protected SparkApplication getApplication(FilterConfig filterConfig) throws ServletException { | |
Class<?>[] configClasses = getConfigClasses(filterConfig); | |
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(configClasses)) { | |
String applicationClassName = filterConfig.getInitParameter(APPLICATION_CLASS_PARAM); | |
try { | |
return (SparkApplication) context.getBean(Class.forName(applicationClassName)); | |
} catch (ClassNotFoundException e) { | |
throw new ServletException(e); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void sendMessage() { | |
Employee employee = new Employee(); | |
employee.setId(counter.incrementAndGet()); | |
employee.setName("name-" + employee.getId()); | |
rabbitTemplate.convertAndSend(employee); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void handleMessage(Employee employee) { | |
LOG.info("handle employee with id {} and name {}", employee.getId(), employee.getName()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Bean | |
public SimpleMessageListenerContainer listenerContainer() { | |
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); | |
container.setConnectionFactory(connectionFactory()); | |
container.setQueueNames(this.employeeQueueName); | |
container.setMessageListener(new MessageListenerAdapter(new MessageHandler(), jsonMessageConverter())); | |
return container; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Bean | |
public ConnectionFactory connectionFactory() { | |
CachingConnectionFactory connectionFactory = new CachingConnectionFactory(); | |
connectionFactory.setAddresses("localhost:5673,localhost:5672"); | |
return connectionFactory; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>com.fasterxml.jackson.jaxrs</groupId> | |
<artifactId>jackson-jaxrs-json-provider</artifactId> | |
<version>2.2.1</version> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework.amqp</groupId> | |
<artifactId>spring-rabbit</artifactId> | |
<version>1.2.0.RELEASE</version> | |
</dependency> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static org.hamcrest.CoreMatchers.is; | |
import static org.junit.Assert.assertNull; | |
import static org.junit.Assert.assertThat; | |
import javax.sql.DataSource; | |
import org.junit.Before; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.springframework.beans.factory.annotation.Autowired; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.sql.DataSource; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
@Configuration | |
public class EmbeddedDataSourceConfig implements DataSourceConfig { | |
@Override | |
@Bean(destroyMethod="shutdown") |
NewerOlder