Guice

java +testNG 接口测试框架搭建------连接数据库(二)

我的未来我决定 提交于 2020-04-23 04:40:51
在编写的测试脚本中导入连接数据的包: import com.alibaba.fastjson.JSONObject; import com.github.yongchristophertang.database.annotations.SqlDB;//注入数据库包 import com.github.yongchristophertang.database.testng.TestNGDBInjectionModuleFactory; import com.github.yongchristophertang.engine.java.ProxyFactories; import com.google.inject.Inject; import com.qiming.qqzw.resource.api.oversea.IHanyuOverSeaSceneService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context

Getting multiple guice singletons of the same type

北城以北 提交于 2020-04-05 15:56:53
问题 can you get 2 singleton instances of the same underlying type? this is obviously trivial in spring as it is based on named instances to which you attach a scope but I can't see the equivalent in guice which is about binding types to implementation classes. Note that I don't want to have to bind to the instance as the instances in question are injected with other dependencies by guice. 回答1: It's easy in Guice too! Create two biding annotations, say @One and @Two and then bind(MySingleton.class

Guice puzzler: Batch scoped Encapsulated Context

孤人 提交于 2020-03-22 06:10:45
问题 We are preparing to begin using Guice in our insurance data conversion platform and I have encountered an interesting scenario that does not seem to be directly addressed in the Guice docs or any postings I have found. Our platform uses the Encapsulated Context (EC) pattern in several important areas. For example, imagine we are processing a set of 10 policies. Whenever we begin processing a new policy, we wish to construct a PolicyContext object and initialize properties such as policy

Why use/develop Guice, when You have Spring and Dagger? [closed]

青春壹個敷衍的年華 提交于 2020-03-17 04:08:45
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 3 years ago . To my knowledge, Dagger does generate code, while Guice and Spring rely on runtime processing, thus Dagger works faster, but requires more work on programmer side. Because of performance edge it's good for mobile (Android) development. However, when we are left with Guice and

Guice: Using parameter in Module (JndiIntegration)

假如想象 提交于 2020-03-05 09:58:26
问题 I've a module like this public class JNDITransactionModule implements Module{ @Override public void configure(Binder binder) { binder.bind(TransactionManager.class) .toProvider( JndiIntegration.fromJndi( TransactionManager.class, "URI TO TRANSACTION MANAGER")) .in(Scopes.SINGLETON); } } Well, I think my question is easy, but... how can I parametrize the "URI TO TRANSACTION MANAGER" value?? I mean, something like this public class JNDITransactionModule implements Module{ @Override public void

Guice: How to change injection on runtime based on a (dynamic web property)

心不动则不痛 提交于 2020-01-30 19:36:07
问题 The following is an approximation of the problem I'm facing. Think we have a password validator with some rules. public interface RuleChecker{ //Checks for a password strenght, returns 10 //for strong or 0 for soft password. int check(String pass); } And then we have several implementations, our service will only accept the password if it is over 8 score. public class NoCheck implements RuleChecker { public int check(String pass){return 10;} } public class LengthCheck implements RuleChecker{

How to prevent reuse of EntityManager with guice-persist and @Transactional?

给你一囗甜甜゛ 提交于 2020-01-25 06:49:27
问题 According to this question, when using guice-persist , EntityManager is transaction-scoped. If I understand correctly, this means that a new EntityManager will be created for every transaction. When using guice-persist , it is suggested to use JpaPersistModule , which provides all the bindings, and simply inject Provider<EntityManager> into some class, like this: public class ProjectDAO { private final Provider<EntityManager> entityManagerProvider; @Inject public ProjectDAO(Provider

How to use Google Guice with Richfaces 4.3.7

喜夏-厌秋 提交于 2020-01-25 05:28:07
问题 I'm programming a web app which uses richfaces 4.3.7 and google guice 4.0. The problem is that richfaces using guava 18 und google guice using guava 16, this results with the following Exception: java.lang.RuntimeException: java.lang.IllegalAccessError: tried to access method com.google.common.collect.MapMaker.makeComputingMap(Lcom/google/common/base/Function;)Ljava/util/concurrent/ConcurrentMap; from class org.richfaces.resource.ResourceLibraryFactoryImpl Caused by: java.lang

How to use Google Guice with Richfaces 4.3.7

天大地大妈咪最大 提交于 2020-01-25 05:28:06
问题 I'm programming a web app which uses richfaces 4.3.7 and google guice 4.0. The problem is that richfaces using guava 18 und google guice using guava 16, this results with the following Exception: java.lang.RuntimeException: java.lang.IllegalAccessError: tried to access method com.google.common.collect.MapMaker.makeComputingMap(Lcom/google/common/base/Function;)Ljava/util/concurrent/ConcurrentMap; from class org.richfaces.resource.ResourceLibraryFactoryImpl Caused by: java.lang

How can I mix Guice and Jersey injection?

微笑、不失礼 提交于 2020-01-24 11:59:05
问题 I've already seen the following question on how to inject @Context dependencies into Jersey resource constructors. But my question is slightly different -- I'd like to inject a @PathParam String. I have a class resembling the following: @Path("foo/{fooId}/bar") public class BarResource { @Inject public BarResource(@PathParam("fooId") String foo, Service service) { ... } ... } The Service is injected fine by Guice, but the path segment is always null. This actually surprises me; if anything I