Ich habe ein Projekt Frühjahr mvc mit Kamel ohne XML-Config-Datei.Kamel Kontext begann zweimal Frühling mvc java config
Mein Problem ist, dass es zwei Kontext gibt: Spring-Stamm WebApplicationContext und Spring FrameworkServlet "Dispatcher", und ein Kamel Kontext wird in jedem Kontext (Camel-1 und Camel-2) mit den gleichen Routen erstellt. Wenn ich also eine Route stoppe oder aussetze, wird sie in nur einem Kontext angehalten oder angehalten (WebApplicationContext). Ich möchte den Kontext nur einmal camel haben. Wie kann ich ?
ApplicationConfiguration.java
package sal.sfs.configuration;
import sal.sfs.security.SfsSessionInfo;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "sal.sfs")
@PropertySource(value = {"classpath:sfs.properties"})
@Import({PersistenceConfiguration.class, SecurityConfiguration.class, SfsCamelConfiguration.class})
public class ApplicationConfiguration extends WebMvcConfigurerAdapter {
@Bean(name = "SFS")
public ViewResolver viewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setSuffix(".zul");
return viewResolver;
}
/*
* Configure ResourceHandlers to serve static resources like CSS/ Javascript etc...
*/
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/css/**").addResourceLocations("/css/");
registry.addResourceHandler("/img/**").addResourceLocations("/img/");
}
}
SfsCamelConfiguration.java
package sal.sfs.configuration;
import java.util.List;
import javax.annotation.Resource;
import org.apache.camel.Route;
import org.apache.camel.spring.javaconfig.CamelConfiguration;
import org.apache.camel.spring.spi.SpringTransactionPolicy;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@Configuration
@ComponentScan("sal.sfs.camel")
@Import(PersistenceConfiguration.class)
public class SfsCamelConfiguration extends CamelConfiguration {
@Resource
PersistenceConfiguration persistenceConfiguration;
@Bean
public SpringTransactionPolicy camelTransactionPolicy() {
SpringTransactionPolicy springTransactionPolicy = new SpringTransactionPolicy();
springTransactionPolicy.setTransactionManager(persistenceConfiguration.transactionManager(persistenceConfiguration.entityManagerFactory().getObject()));
springTransactionPolicy.setPropagationBehaviorName("PROPAGATION_REQUIRED");
return springTransactionPolicy;
}
}
SecurityWebApplicationInitializer.java
package civadis.salaires.sfs.configuration;
import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer;
public class SecurityWebApplicationInitializer extends AbstractSecurityWebApplicationInitializer {
}
SpringMvcInitializer.java
package sal.sfs.configuration;
import javax.servlet.Filter;
import org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
public class SpringMvcInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class[]{ApplicationConfiguration.class};
}
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class[]{ApplicationConfiguration.class};
}
@Override
protected String[] getServletMappings() {
return new String[]{"/", "*"};
}
/*
Also we have registered OpenEntityManagerInViewFilter to enable lazy loading of JPA entity graphs in view rendering phase
*/
@Override
protected Filter[] getServletFilters() {
return new Filter[]{
new OpenEntityManagerInViewFilter()
};
}
}
Welche Version von Camel verwenden Sie? Versuchen Sie es mit der neuesten Version –
Hallo Claus, ich benutze die letzte Version von Camel 2.17.2 mit Feder Version 4.2.5. – catciv