zoukankan      html  css  js  c++  java
  • 看看什么是Guice

    mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

    MAVEN 创建一个eclipse

    import com.google.inject.ImplementedBy;
    
    @ImplementedBy(HelloGuiceImpl.class)
    public interface IHelloGuice {
        public boolean check();
    }
    public class HelloGuiceImpl implements IHelloGuice {
    
        @Override
        public boolean check() {
            System.out.println("Hello");
            return false;
        }
    
    }
    import com.google.inject.Binder;
    import com.google.inject.Module;
    public class HelloGuiceModule implements Module {
    
        @Override
        public void configure(Binder arg0) {
            arg0.bind(IHelloGuice.class).to(HelloGuiceImpl.class);
        }
    
    }
    import com.google.inject.Guice;
    import com.google.inject.Injector;
    public class App {
        public static void main(String[] args) {
            // simple 01
            /*
            Injector injector = Guice.createInjector(new HelloGuiceModule());
            IHelloGuice helloGuice = injector.getInstance(IHelloGuice.class);
            helloGuice.check();
            */
            
            Injector injector = Guice.createInjector();
            IHelloGuice helloGuice = injector.getInstance(IHelloGuice.class);
            helloGuice.check();
        }
    }
  • 相关阅读:
    第五章 条件语句
    第四章 javaScript运算符
    第三章 javaScript数据类型
    看电影学英语十
    英语口语会话十
    看电影学英语九
    英语口语会话九
    英语口语会话八
    看电影学英语八
    Linux command line and shell scripting buble
  • 原文地址:https://www.cnblogs.com/lwer/p/3838553.html
Copyright © 2011-2022 走看看