java service 初始化,采用javaConfig 配置AnnotationBean导致 controller,service等bean 重复初始化。...

`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 //

// @EnableAspectJAutoProxy

@componentscan(basePackages = "com.lincomb.linktown.front.controller",excludeFilters = {@componentscan.Filter(type = FilterType.ANNOTATION, value = Service.class)

,@componentscan.Filter(type = FilterType.ANNOTATION, value =Configuration.class)

})

//@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);

}

`

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值