Comments (13)
@iwangxiaodong @hazendaz What do you think about something like this:
private static final String DEFAULT_JNDI_NAME = "java:comp/BeanManager";
private static final AtomicBoolean INITIALIZED = new AtomicBoolean(false);
private static String jndiName = DEFAULT_JNDI_NAME;
private static void init() {
if (!INITIALIZED.getAndSet(true)) {
synchronized (DEFAULT_JNDI_NAME) {
try {
if (InitialContext.doLookup("java:comp/env/BeanManager") != null) {
jndiName = "java:comp/env/BeanManager";
}
} catch (NamingException e) {
// Fallback to default, do nothing
}
}
}
}
private static BeanManager getBeanManager() {
init();
try {
return InitialContext.doLookup(jndiName);
} catch (NamingException e) {
throw new RuntimeException(e);
}
}
from cdi.
Good catch! This would affect tomcat too as its jndi is read only as well. So bean manager is going to be in the location you noted above. I'd say drop back to 1.0.0 release for time being.
from cdi.
I copied CDIUtils.java and modified it as follows:
private static BeanManager getBeanManager() {
try {
return InitialContext.doLookup("java:comp/BeanManager");
} catch (NamingException e) {
try {
return InitialContext.doLookup("java:comp/env/BeanManager");
} catch (NamingException ex) {
throw new RuntimeException(ex);
}
}
}
It works fine!
from cdi.
@iwangxiaodong Can you kindly send a PR for this. Thanks. I've used this exact same thing for JNDI many times in the past. While not the most efficient, given it hits multiple container types it's probably the easiest.
from cdi.
@iwangxiaodong @hazendaz It would be nice if we can cache at least the jndi name. but maybe it requires some synchronization. I think throwing exceptions and catching them every time this method is called is a lot of overhead. We have to decide what is less bad: synchronization vs try/catch. Or maybe we can statically do a lookup when the class is loaded and save the correct jndi name, so we will not require sync or try/catch inside the method.
from cdi.
@iwangxiaodong @hazendaz Or even better:
public final class CDIUtils {
private static class JNDI {
private static final String DEFAULT_JNDI_NAME = "java:comp/BeanManager";
static final String NAME;
static {
String jndiName = DEFAULT_JNDI_NAME;
try {
if (InitialContext.doLookup("java:comp/env/BeanManager") != null) {
jndiName = "java:comp/env/BeanManager";
}
} catch (NamingException e) {
// Fallback to default, do nothing
}
NAME = jndiName;
}
}
private static BeanManager getBeanManager() {
try {
return InitialContext.doLookup(JNDI.NAME);
} catch (NamingException e) {
throw new RuntimeException(e);
}
}
from cdi.
@mnesarco @hazendaz This code is very good performance!
from cdi.
@iwangxiaodong Thanks for the catch. I will submit the patch just now.
from cdi.
@mnesarco Yeah! Nice!
from cdi.
from cdi.
@iwangxiaodong @mnesarco I have released version 1.0.2 with this change. It should show in central in about 2 hours but is otherwise available for download now.
from cdi.
from cdi.
compile 'org.mybatis:mybatis-cdi:1.0.2'
I tested OK!
from cdi.
Related Issues (20)
- UnsatisfiedResolutionException: Api type [] is not found with the qualifiers... HOT 7
- Consider support JNDI obtain UserTransaction?
- Weld 3.1.7.Final Proxy changes has broken mybatis-cdi support HOT 1
- Create annotation to rollback exception by default HOT 1
- Upgrade to jakarta Namespace HOT 17
- UnsatisfiedResolutionException using aries-cdi 1.1.5 with karaf 4.3.7 HOT 1
- Dependency Dashboard
- Migrate from atomikos to narayana HOT 1
- Site plugin and 'clirr' usage issue with jakarta
- Clirr: Remove profile from maven.config file after no longer needing to compare to javax namespace
- missing @Any qualifier on MybatisBean if user provided qualifier is present
- Transactional (mybatis-cdi: org.mybatis.cdi.Transactional) annotation with rollbackOnly=true not rollbacking transactions inside a Weld / JUnit 5 test
- issue with micro profile standard HOT 1
- Release 1.0.3 HOT 4
- NoSuchElementException in test with Arquillian and embedded container HOT 10
- "WELD-001328: Unable to identify the correct BeanManager." occurs HOT 16
- Test issues - 8 of 13 can run concurrently / recent updates do not support oldest support revision of cdi/weld HOT 5
- github is behaving very strange... HOT 1
- mybatis-cdi-1.0.3 crashes in repeated requests HOT 2
- Release mybatis-cdi 1.1.0 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cdi.