Tag: 代码注入

从eclipse为PhoneGap调用javascript

我正在尝试使用以下代码在Android上使用Phonegap加载网站: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.setBooleanProperty(“loadInWebView”, true); super.loadUrl(“http://arriva.com.mt”); } 我如何在webview上执行本地javascript文件?

CDI – ApplicationScoped但已配置

问题 使用CDI我想生成@ApplicationScoped bean。 另外,我想为注入点提供配置注释,例如: @Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) @Retention(RetentionPolicy.RUNTIME) public @interface Configuration { String value(); } 我不想为每种不同的value可能性写一个单独的生产者。 途径 通常的方法是制作一个制作人并处理注入点注释: @Produces public Object create(InjectionPoint injectionPoint) { Configuration annotation = injectionPoint.getAnnotated().getAnnotation(Configuration .class); … } 因此,bean不再是应用程序作用域,因为每个注入点可能可能不同(生产者的参数注入点不适用于@AplicationScoped注释的生产者)。 所以这个解决方案不起作用。 题 我需要一个具有相同值的注入点获得相同bean实例的可能性。 是否有内置的CDI方式? 或者我是否需要在列表中以某种方式“记住”bean,例如在包含生产者的类中? 我需要的是基本上每个不同value的ApplicationScoped实例。

使用dropwizardvalidation,我可以访问数据库以插入记录

我的问题如下: 我正在使用dropwizard进行项目,到目前为止,我已经愉快地成功使用了validation框架。 我的validation工作正常,它以标准方式使用。 这就是我所拥有的: 请求类: import javax.validation.constraints.NotNull; import MandatoryFieldLengthCheck; public class InitiatePaymentRequest implements PaymentRequest { @NotNull(message = “Mandatory input field missing”) @MandatoryFieldLengthCheck(value = 32) protected String transactionId; } 然后是注释类: @Target({ METHOD, FIELD, ANNOTATION_TYPE }) @Retention(RUNTIME) @Constraint(validatedBy = MandatoryFieldLengthCheckValidator.class) @Documented public @interface MandatoryFieldLengthCheck { String message() default “Invalid input data”; Class[] groups() default {}; Class[] payload() […]

guice:命令行的运行时注入/绑定

我有以下问题: @Inject MyClass(Service service) { this.service = service; } public void doSomething() { service.invokeSelf(); } 我有一个模块 bind(service).annotatedWith(Names.named(“serviceA”).to(ServiceAImpl.class); bind(service).annotatedWith(Names.named(“serviceB”).to(ServiceBImpl.class); 现在我的问题是我希望允许用户通过命令行参数动态选择运行时基础上的注入。 public static void Main(String args[]) { String option = args[0]; ….. } 我怎么能这样做? 我是否必须创建多个模块才能执行此操作?

使用Haskell将函数注入Java .class文件

我使用Haskell编写了一个Java字节码解析器,它运行得很好。 然而,下一步让我完全难过。 我的Haskell程序需要修改.class文件,以便在执行时,Java程序打印: “在执行方法之前输入[此处的方法名称] ”,和 执行方法后“ 退出[此处的方法名称] ”。 我所知道的是,我们需要通过调用System.out.println来附加常量池和方法表,但我觉得我仍然缺少一些东西。 解决这个问题的最佳方法是什么? 你怎么知道如何在字节码中调用System.out.println ? 如何使用方法名称存储字符串,以后将其作为System.out.println的参数调用?

Java ASM字节码修改 – 更改方法体

我在jar子里有一个类的方法,我想用自己的身体交换它。 在这种情况下,我只想让方法打印出“GOT IT”到控制台并返回true; 我正在使用系统加载程序来加载jar的类。 我使用reflection使系统类加载器能够通过字节码加载类。 这部分似乎工作正常。 我按照这里找到的方法替换示例:asm.ow2.org/current/asm-transformations.pdf。 我的代码如下: public class Main { public static void main(String[] args) { URL[] url = new URL[1]; try { url[0] = new URL(“file:////C://Users//emist//workspace//tmloader//bin//runtime//tmgames.jar”); verifyValidPath(url[0]); } catch (Exception ex) { System.out.println(“URL error”); } Loader l = new Loader(); l.loadobjection(url); } public static void verifyValidPath(URL url) throws FileNotFoundException { File filePath […]

在Java中扩展generics类型

在Java中是否可以让类扩展generics类型,以便您可以将方法注入到通过代码传递的任何类中? (或者有没有其他方法可以使用Java将方法注入或覆盖到现有类中?) 我对“扩展generics类型”的意思是这样的(类“T extends GameObject”属于游戏,可能不会被更改并且因为在运行时加载到游戏中而未知(来自其他mod)): class GameObject { void moveForward(float amount) { this.camera.z += amount; } } class Extender extends T { void onTick(float time) { this.camera.z -= amount; } } onTick由GameEngine调用,通过这种方式,我可以用每个tick上向后移动的版本替换每个现有的游戏对象。

JUnit中的Guice注入器测试

使用Guice,在每个JUnit测试类中获取一个新的注入器是一个好习惯,因为每个测试类应该是独立的吗?

用Spring Annotation替换

有一种方法可以用Annotation替换constructor-arg吗? 我有这个构造函数: public GenericDAOImpl(Class type) { this.type = type; } 我需要在我的Facade中注入: @Inject private GenericDAO autoDao; 问题是我不知道如何在costructor中传递参数的值。 先感谢您 [更多信息]我试着解释我的问题。 genericdaotest.domain.Person 我想只使用注释转换该代码。 有人可以解释一下吗?

Spring @Autowired是按名称还是按类型注入bean?

我正在读初春(威利出版社)的书。 在第2章中有一个关于Java配置和@Autowired的示例。 它提供了这个@Configuration类 @Configuration public class Ch2BeanConfiguration { @Bean public AccountService accountService() { AccountServiceImpl bean = new AccountServiceImpl(); return bean; } @Bean public AccountDao accountDao() { AccountDaoInMemoryImpl bean = new AccountDaoInMemoryImpl(); //depedencies of accountDao bean will be injected here… return bean; } @Bean public AccountDao accountDaoJdbc() { AccountDaoJdbcImpl bean = new AccountDaoJdbcImpl(); return bean; } […]