`public class LDFrontWebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
/**
* 指定 Root WebApplicationContext 类,这个类必须@Configuration来注解,从而代替XML配置文件
*/
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class<?>[]{RootConfig.class};
}
/**
* 指定 Servlet WebApplicationContext 类,这个类必须@Configuration来注解,从而代替XML配置文件
*/
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class<?>[]{WebMvcConfig.class};
}
/**
* 指定 Servlet mappings
*/
@Override
protected String[] getServletMappings() {
return new String[]{"/"};
}
}
//@Order(2)
@Configuration
@EnableWebMvc //
}) //@PropertySource(value = { "classpath:config.properties" }) //@Import(DubboConfig.class) public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Bean
public static AnnotationBean annotationBean() {
AnnotationBean annotationBean = new AnnotationBean();
annotationBean.setPackage("com.lincomb.linktown.front");
return annotationBean;
}
..............................
` @Configuration @ComponentScan(basePackages = "com.lincomb.linktown.front" ,excludeFilters = { @ComponentScan.Filter(type = FilterType.ANNOTATION, value = RestController.class),@ComponentScan.Filter(type = FilterType.ANNOTATION, value = Configuration.class)}) @PropertySource(value = { "classpath:config.properties" }) //@ImportResource({ "classpath:spring-redis.xml", "classpath:spring-fastdfs.xml" }) public class RootConfig {
//@Autowired LinktownConfig linktownConfig;
/**
* 注入dubbo上下文
*
* @return
*/
@Bean
public ApplicationConfig applicationConfig() {
// 当前应用配置
ApplicationConfig applicationConfig = new ApplicationConfig();
applicationConfig.setName("ld-counsmss");
return applicationConfig;
}
/**
* 注入dubbo注册中心配置,基于zookeeper
*
* @return
*/
@Bean
public RegistryConfig registryConfig() {
// 连接注册中心配置
RegistryConfig registry = new RegistryConfig();
registry.setProtocol("zookeeper");
registry.setAddress("172.16.107.217:2181,172.16.107.218:2181,172.16.107.219:2181");
return registry;
}
``
`package com.lincomb.linktown.front.service;
import javax.annotation.PostConstruct;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
@Service @Slf4j public class HelloServiceImpl implements HelloService {
// @Reference IAdvertService advertService;
public HelloServiceImpl() {
super();
log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>HelloServiceImpl构造器>>>>");
}
@PostConstruct
public void aa(){
log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>initHelloServiceImpl>>>>");
// log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>initHelloServiceImpl ---advertService>>>>"+advertService);
}
`