Announcement Announcement Module
Collapse
No announcement yet.
is ther a bug? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • is ther a bug?

    in my beans.xml file have:


    <bean class="org.springframework.jdbc.datasource.DriverM anagerDataSource" id="dataSource">
    <property name="driverClassName">
    <value>
    com.mysql.jdbc.Driver
    </value>
    </property>
    <property name="url">
    <value>
    jdbc:mysql://localhost/jpetstore
    </value>
    </property>
    <property name="username">
    <value>root</value>
    </property>
    <property name="password">
    <value>root</value>
    </property>
    </bean>
    ________________
    then get the follow error:

    I chang it :

    public void setDriverClassName(String driverClassName) throws CannotGetJdbcConnectionException {
    if (!StringUtils.hasText(driverClassName)) {
    throw new IllegalArgumentException("driverClassName must not be empty");
    }
    this.driverClassName = driverClassName;===>
    this.driverClassName = driverClassName.trim();

    its ok.


    Exception in thread "main" org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'dataSource' defined in class path resource [businessLayer-context.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyAccessExceptions Exception: PropertyAccessExceptionsException (1 errors); nested propertyAccessExceptions are: [org.springframework.beans.MethodInvocationExceptio n: Property 'driverClassName' threw exception; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionEx ception: Could not load JDBC driver class [
    com.mysql.jdbc.Driver
    ]; nested exception is java.lang.ClassNotFoundException:
    com.mysql.jdbc.Driver
    ]
    PropertyAccessExceptionsException (1 errors)
    org.springframework.beans.MethodInvocationExceptio n: Property 'driverClassName' threw exception; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionEx ception: Could not load JDBC driver class [
    com.mysql.jdbc.Driver
    ]; nested exception is java.lang.ClassNotFoundException:
    com.mysql.jdbc.Driver

    org.springframework.jdbc.CannotGetJdbcConnectionEx ception: Could not load JDBC driver class [
    com.mysql.jdbc.Driver
    ]; nested exception is java.lang.ClassNotFoundException:
    com.mysql.jdbc.Driver

    java.lang.ClassNotFoundException:
    com.mysql.jdbc.Driver

    at java.net.URLClassLoader$1.run(URLClassLoader.java: 200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 06)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:268)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 51)
    at java.lang.ClassLoader.loadClassInternal(ClassLoade r.java:319)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:242)
    at org.springframework.jdbc.datasource.DriverManagerD ataSource.setDriverClassName(DriverManagerDataSour ce.java:129)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:814)
    at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:716)
    at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:850)
    at org.springframework.beans.BeanWrapperImpl.setPrope rtyValues(BeanWrapperImpl.java:877)
    at org.springframework.beans.BeanWrapperImpl.setPrope rtyValues(BeanWrapperImpl.java:866)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:901)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:707)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:316)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:222)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:146)
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:277)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:310)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:80)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:65)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:56)
    at test.main(test.java:26)

  • #2
    Why not just be happy with:
    Code:
    <value>com.mysql.jdbc.Driver</value>
    or even better, making use of PropertyPlaceholderConfigurer:
    Code:
    <value>$&#123;jdbc.driver&#125;</value>
    Lawrence

    Comment


    • #3
      hhh,I generate it with velocity

      after generate, the xml file become like that,how can i do?

      I use a domparser to read.

      Comment

      Working...
      X