我正在尝试使用弹簧数据构造一个LdapTemplate对象。
public class LDAPTemplate {
public static void main(String[] args) {
LdapContextSource lcs = new LdapContextSource();
lcs.setUrl("ldap://localhost:389/");
lcs.setUserDn("cn=Manager, dc=example, dc=com");
lcs.setPassword("secret1");
lcs.setDirObjectFactory(DefaultDirObjectFactory.class);
LdapTemplate ldap = new LdapTemplate(lcs);
ldap.lookup("cn=aaa");
}
}
Run Code Online (Sandbox Code Playgroud)
我想知道的是实例化ldap模板对象的正确方法。因为当我执行查找时,它会抛出NPE。
我正在尝试在CDI上下文中使用LDAP Spring,而根本不使用spring。如果您有指针,那就太好了。Spring LDAP是否依赖于spring?
请帮助我理解为什么对象没有得到以下代码的持久性.它抛出javax.persistence.TransactionRequiredException:JBAS011469:执行此操作需要事务(使用事务或扩展持久性上下文)
public class OrganizationRepositoryImpl implements OrganizationRepository {
@PersistenceContext(unitName="usermanagement",type=PersistenceContextType.TRANSACTION)
private EntityManager em;
public void save(Organization organization) {
try {
em.persist(organization);
}catch(Exception e) {
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是如果我用@Stateless注释(Now ejb)注释该类,则对象开始变为持久化
@Stateless
public class OrganizationRepositoryImpl implements OrganizationRepository {
@PersistenceContext(unitName="usermanagement",type=PersistenceContextType.TRANSACTION)
private EntityManager em;
public void save(Organization organization) {
try {
em.persist(organization);
}catch(Exception e) {
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud)
persistence.xml中
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="usermanagement" transaction-type="JTA">
<jta-data-source>java:jboss/datasources/MysqlXADS</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property …Run Code Online (Sandbox Code Playgroud) 请帮我解决这个问题。
void setCreateSessionAllowed(boolean createSessionAllowed)
的方法
org.springframework.security.web.savedrequest.HttpSessionRequestCache
类说
如果为 true,则表示允许在新的 HttpSession(默认)中存储目标 URL 和异常信息。在您不希望创建不必要的 HttpSession 的情况下(因为用户代理会知道失败的 URL,例如使用 BASIC 或 Digest 身份验证),您可能希望将此属性设置为 false。
所以我没有正确理解描述,而且我们正在使用一个产品,它的文档说将其设置为 false 将禁用匿名用户会话的创建。所以我的问题是,会话创建并将其与请求关联是 servlet 容器的工作。那么为什么使用这个方法(setCreateSessionAllowed)不会创建会话。 请验证我的理解是否正确。还
setCreateSessionAllowed(false), JSESSIONID 是否创建?