Code Monkey home page Code Monkey logo

Comments (5)

WillWang2015 avatar WillWang2015 commented on July 25, 2024

找到原因了,DisconfAspectJ只会在enable.remote.conf=true的时候才会进行切面。
配置Bean加上@DisconfFile后已经变为一个proxy bean,这样读取的配置就不能被正确注入,所以都是null。
难道annotation的bean不能使用本地配置?不解。

from disconf.

WillWang2015 avatar WillWang2015 commented on July 25, 2024

验证发现,把所有的静态的,动态托管的配置文件放在本地classpath,设置enable.remote.conf=true
conf_server_host设置为一个错误的地址,这样才能都正确使用本地的配置运行。
@knightliao 能否解释下这个问题。
因为有很多配置项,开发人员每个人都有自己的环境,配置项会不同。我希望所有的配置文件都放在本地classpath中,作为Local开发配置,可以个人修改。其他环境使用disconf远程配置。

from disconf.

knightliao avatar knightliao commented on July 25, 2024

hi 功能上应该是没有问题的。

  1. 因为配置bean实例的field亦会被注入值,即便配置Bean加上@DisconfFile后已经变为一个proxy bean,也可以正确找到对应的bean并注入
  2. 你可以跑下 https://github.com/knightliao/disconf-demos-java/tree/master/disconf-standalone-demo 这个demo试试?把配置下下来,然后本地跑试试。
  3. 有问题可以再联系我

from disconf.

WillWang2015 avatar WillWang2015 commented on July 25, 2024

@knightliao 感谢反馈。
annotation的使用本地文件配置功能确实有问题。我使用了 https://github.com/knightliao/disconf-demos-java/tree/master/disconf-standalone-demo 进行了测试。
拉取了 https://github.com/knightliao/disconf-demos-java/tree/master/disconf-standalone-demo/conffiles 所有的文件到classpath。
运行日志如下:

2016-01-14 10:04:58,972 [main] INFO  com.example.disconf.demo.task.DisconfDemoTask - baobao--baifa: 5200.0
2016-01-14 10:04:58,972 [main] INFO  com.example.disconf.demo.task.DisconfDemoTask - baobao--yuerbao: 5200.0
2016-01-14 10:05:03,978 [main] INFO  com.example.disconf.demo.task.DisconfDemoTask - redis( 127.0.0.1 , 6379 ) get key : disconf_key
2016-01-14 10:05:03,978 [main] INFO  com.example.disconf.demo.task.DisconfDemoTask - redis( 127.0.0.1 , 6379 )
2016-01-14 10:05:03,990 [main] INFO  com.example.disconf.demo.task.DisconfDemoTask - code config:
2016-01-14 10:05:03,990 [main] INFO  com.example.disconf.demo.task.DisconfDemoTask - autoservice: bbd
2016-01-14 10:05:03,990 [main] INFO  com.example.disconf.demo.task.DisconfDemoTask - autoservice2: cc
2016-01-14 10:05:03,990 [main] INFO  com.example.disconf.demo.task.DisconfDemoTask - static file data: 147
2016-01-14 10:05:03,990 [main] INFO  com.example.disconf.demo.task.DisconfDemoTask - static item data: 56

可以看到code.properties中的属性是空。与我在自己的project中测试跟踪到的问题一致。

from disconf.

knightliao avatar knightliao commented on July 25, 2024

hi,

  1. 从日志中你也可以看到,除了 code.properties有问题外,其它的配置都是正确的(他们也是采用annotation), 所以 整体上是没有问题的,code.properties 是个例,下面我们来看下code.properties
  2. codeConfig的代码是

@service
@DisconfFile(filename = "code.properties", copy2TargetDirPath = "disconf")
public class CodeConfig {

private String codeError = "";

@DisconfFileItem(name = "syserror.paramtype", associateField = "codeError")
public String getCodeError() {
    return codeError;
}

public void setCodeError(String codeError) {
    this.codeError = codeError;
}

}

路径是 copy2TargetDirPath = "disconf" 你把 code.properties放到 disconf目录下(resouce/disconf)下,就OK了

from disconf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.