小编ktm*_*124的帖子

Spring LDA:contextSource Bean的问题

我正在编写一个使用LDAP的Spring应用程序.这是我的bean文件.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

   <bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource">
      <property name="url" value="xxxxx:xxx" />
      <property name="base" value="ou=xxxxx,dc=xxxxxxx,dc=xxxxxx" />
      <property name="userDn" value="uid=xxxxxxx" />
      <property name="password" value="xxxxxxxx" />
   </bean>

   <bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
      <constructor-arg ref="contextSource" />
   </bean>

   <bean id="helloLdap" class="a.b.c.HelloLdap">
      <property name="ldapTemplate" ref="ldapTemplate" />
   </bean>

</beans>
Run Code Online (Sandbox Code Playgroud)

这是我的bean创建代码:

ApplicationContext fac = new ClassPathXmlApplicationContext(
                "a/b/c/ldap.xml");
HelloLdap hello = (HelloLdap) fac.getBean("helloLdap");
Run Code Online (Sandbox Code Playgroud)

这是我的错误消息:

线程"main"org.springframework.beans.factory.BeanCreationException中的异常:在类路径资源[xxxxxxxxxxxx]中定义名称为'contextSource'的bean时出错:设置属性值时出错; 嵌套异常是org.springframework.beans.PropertyBatchUpdateException; 嵌套的PropertyAccessExceptions(1)是:PropertyAccessException 1:org.springframework.beans.MethodInvocationException:属性'base'抛出异常; 嵌套异常是java.lang.NoClassDefFoundError:org/apache/commons/lang/StringUtils

所以它说(最重要的)

"Property 'base' threw exception". 
Run Code Online (Sandbox Code Playgroud)

我想知道这是否是因为身份验证需要StartTLS.我没有在我的beans文件中的任何地方指示StartTLS身份验证,因此可能导致错误.不过,我希望在创建bean 之后,而不是在创建bean期间进行身份验证.

有谁知道这是不是原因(StartTLS authenticaton)?如果没有,任何想法我在我的XML中做错了什么?

谢谢,ktm

java xml spring ldap spring-ldap

3
推荐指数
1
解决办法
5320
查看次数

SQL样式问题:FROM子句或WHERE子句中的INNER JOIN?

如果要在SQL查询中连接多个表,您认为在哪里放置连接语句更好:在FROM子句或WHERE子句中?

如果您要在FROM子句中执行此操作,那么如何对其进行格式化以使其清晰可读?(我说的是缩进,换行,一般的空格.)

每个都有任何优点/缺点吗?

sql database

3
推荐指数
2
解决办法
5254
查看次数

Spring/LDAP - 在bean配置中调用setter方法

我正在编写Spring LDAP应用程序,我必须为ContextSource设置身份验证策略.我想在我的bean XML文件中执行此操作.在为好的ContextSource JavaDoc的说,它有一个叫做setter方法

setAuthenticationStrategy(
    DirContextAuthenticationStrategy authenticationStrategy
)
Run Code Online (Sandbox Code Playgroud)

要从我的beans文件调用此setter,以下XML是否足够?

<bean id="authStrategy"
    class="org.springframework...DefaultTlsDirContextAuthenticationStrategy">
 ...
</bean>

<bean id="contextSource"
    class="org.springframework.ldap.core.support.LdapContextSource">

    <property name="url" ... />
    <property name="base" ... />
     ...
    <property name="authenticationStrategy" ref="authStrategy" /> 
</bean>
Run Code Online (Sandbox Code Playgroud)

也就是说,究竟是什么决定了方法的调用setAuthenticationStrategy?这是我的财产名称authenticationStrategy吗?Spring会自动将属性名称转换为适当的setter方法吗?

java spring javabeans spring-ldap

3
推荐指数
1
解决办法
4836
查看次数

Spring-MVC:是否有可能为一个servlet映射提供两个url模式?

我有.htm和.xml URL我想在WEB-INF文件夹中解析为.jsp文件.如何指定我希望相同的servlet同时处理*.htm和*.xml URL?

java spring-mvc

3
推荐指数
1
解决办法
1万
查看次数

Java String.matches正则表达式与OR管道

我正在尝试进行以下匹配,但它没有像我期望的那样返回true:

String attrs = "id|fullname|email|title";
String regex = "fullname|email";
return attrs.matches(regex);
Run Code Online (Sandbox Code Playgroud)

相反,它返回false.

为什么是这样?我期待| attrs中的管道按字面解释为ASCII字符,以及| 正则表达式中的管道根据正则表达式(即OR)进行解释.

我问的原因是因为我正在编写一个应用程序,我让用户以attr1 | attr2 | attr3 | ...的格式设置属性,我想通过将它与可能的属性值进行匹配来验证他/她的输入: attR1位| attR2位| attr3 | ... | ATTR [N].

帮助赞赏,
ktm


通过这样做工作

String regex = "id.*|fullname.*|email.*|title.*";
String attrs = "fullname|email";
return attrs.matches(regex);
Run Code Online (Sandbox Code Playgroud)

java regex

2
推荐指数
2
解决办法
2万
查看次数

Spring - 所有bean都被处理了吗?

我有一个我正在编写的LDAP应用程序的beans.xml文件.我允许用户选择几个LdapContextSource.对于每一个我有一个不同的豆,例如

<bean id="ldapTemplate" class="yyy.LdapTemplate">
      <constructor-arg ref="contextSource1" />
</bean>
<bean id="contextSource1" class="xxx.LdapContextSource">
      ...
</bean>
<bean id="contextSource2" class="xxx.LdapContextSource">
      ...
</bean>
<bean id="contextSource3" class="xxx.LdapContextSource">
      ...
</bean>
Run Code Online (Sandbox Code Playgroud)

您可以看到只有一个上下文源bean被实例化,因为ldapTemplate bean只引用了一个.但是,当我运行我的应用程序时,stdout中的Spring日志消息提供了有关每个上下文源的信息,即使只依赖于其中一个.

2011年1月25日上午11:56:36 org.springframework.ldap.core.support.AbstractContextSource afterPropertiesSet INFO:未设置属性'userDn' - 匿名上下文将用于读写操作Jan 25,2011 11:56:37 AM org.springframework.ldap.core.support.AbstractContextSource afterPropertiesSet INFO:未设置属性'userDn' - 匿名上下文将用于读写操作2011年1月25日上午11:56:37 org.springframework.ldap.core. support.AbstractContextSource afterPropertiesSet INFO:未设置属性'userDn' - 匿名上下文将用于读写操作

我的问题是:

(1)Spring使用未引用/依赖的上下文源做什么?它们永远不应该在我的应用程序中实例化,它让我担心Spring正在为每个bean提供日志信息.

(2)我应该注释掉应用程序中未使用的上下文源bean吗?让他们没有注释会有什么后果?什么是标准做法?

谢谢,
ktm

java spring ldap spring-ldap

2
推荐指数
1
解决办法
866
查看次数

PL/SQL TEXT_IO包

我试图从PL/SQL脚本写入本地文件.为了做到这一点,我试图在PL/SQL中使用TEXT_IO包.

DECLARE
file_out text_io.file_type;
len number;
blob_file blob;
my_var RAW(50);
bstart NUMBER := 1;
bytelen NUMBER := 50;

BEGIN

SELECT xxx
INTO blob_file
FROM yyy
WHERE zzz

dbms_lob.read(blob_file, bytelen, bstart, my_var);    
file_out := text_io.fopen('local_file_path', 'w');
text_io.put_raw(file_out, my_var);
text_io.fflush(file_out);
text_io.fclose(file_out);

END;
/

quit
Run Code Online (Sandbox Code Playgroud)

但是,当我运行此脚本时,我收到错误,

PLS-00201: identifier 'TEXT_IO.FILE_TYPE' must be declared
Run Code Online (Sandbox Code Playgroud)

有谁知道我如何解决这个错误,以及如何将blob的内容写入文件,因为我正在尝试?

谢谢,
ktm

sql oracle plsql sqlplus

2
推荐指数
1
解决办法
2万
查看次数

索引MySQL列可以改进LIKE搜索吗?

我正在使用我在其他地方下载的表,并且他们放了一个名为DATA_SOURCE连接记录的所有不同数据源的列,如下所示:

sourceA; sourceB; sourceC; ...

所以,如果我正在寻找记录sourceB,我将不得不做一个像搜索%sourceB%.

这显然是一个耗时的查询.我的问题是,如果我要索引列DATA_SOURCE,它会改善搜索这些通配符的性能吗?或者它不会有所作为.

mysql sql

2
推荐指数
1
解决办法
60
查看次数

如何更换新线

不幸的是,我在替换新线路时遇到了一些困难.

public class Example {

    static String s = "73167176531330624919225119674426574742355349194934\n" +
        "96983520312774506326239578318016984801869478851843\n" +
        "85861560789112949495459501737958331952853208805511\n" +
        "12540698747158523863050715693290963295227443043557\n" +
        "66896648950445244523161731856403098711121722383113\n" +
        "62229893423380308135336276614282806444486645238749\n" +
        "30358907296290491560440772390713810515859307960866\n" +
        "70172427121883998797908792274921901699720888093776\n" +
        "65727333001053367881220235421809751254540594752243\n" +
        "52584907711670556013604839586446706324415722155397\n" +
        "53697817977846174064955149290862569321978468622482\n" +
        "83972241375657056057490261407972968652414535100474\n" +
        "82166370484403199890008895243450658541227588666881\n" +
        "16427171479924442928230863465674813919123162824586\n" +
        "17866458359124566529476545682848912883142607690042\n" +
        "24219022671055626321111109370544217506941658960408\n" +
        "07198403850962455444362981230987879927244284909188\n" +
        "84580156166097919133875499200524063689912560717606\n" +
        "05886116467109405077541002256983155200055935729725\n" +
        "71636269561882670428252483600823257530420752963450".replaceAll("\\n", "");

    public static void main(String[] args) {
        System.out.println(s);
    }
}    
Run Code Online (Sandbox Code Playgroud)

我想\n从String中删除所有出现的内容s.我尝试在StackOverflow上查找答案,但每个帖子似乎都有不同的答案(而且它们都很复杂且难以记住).

有一个简单的方法吗?


我也试过了

replaceAll("\n", "")
replaceAll("\\\\n", "")
replaceAll(System.getProperty("line.separator"), "")
replaceAll("(\\r|\\n)", "")
Run Code Online (Sandbox Code Playgroud)

java string

2
推荐指数
1
解决办法
140
查看次数

创建 9999 年 12 月 31 日(UTC)的 java.sql.Date 的最简单方法?

我想创建一个 java.sql.Date 为 9999 年 12 月 31 日(UTC)。目前我正在使用这个:

Date eot = new Date(new GregorianCalendar(9999, Calendar.DECEMBER, 31).getTimeInMillis());
Run Code Online (Sandbox Code Playgroud)

然而,它让我觉得丑陋。有没有更简单的方法?

java date

2
推荐指数
1
解决办法
3141
查看次数

标签 统计

java ×7

spring ×3

spring-ldap ×3

sql ×3

ldap ×2

database ×1

date ×1

javabeans ×1

mysql ×1

oracle ×1

plsql ×1

regex ×1

spring-mvc ×1

sqlplus ×1

string ×1

xml ×1