2017-08-10 21 views
1

私は春に新しいですし、私はエラー作成中にエラーが発生しましBean名「T」

WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 't' defined in class path resource [resources/spring.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'driver' of bean class [beans.Test]: Bean property 'driver' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter? 
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 't' defined in class path resource [resources/spring.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'driver' of bean class [beans.Test]: Bean property 'driver' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter? 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1568) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1276) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) 
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) 
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83) 
    at test.Client.main(Client.java:10) 
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'driver' of bean class [beans.Test]: Bean property 'driver' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter? 
    at org.springframework.beans.BeanWrapperImpl.createNotWritablePropertyException(BeanWrapperImpl.java:243) 
    at org.springframework.beans.AbstractNestablePropertyAccessor.processLocalProperty(AbstractNestablePropertyAccessor.java:437) 
    at org.springframework.beans.AbstractNestablePropertyAccessor.setPropertyValue(AbstractNestablePropertyAccessor.java:292) 
    at org.springframework.beans.AbstractNestablePropertyAccessor.setPropertyValue(AbstractNestablePropertyAccessor.java:280) 
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:95) 
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:75) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1564) 
    ... 13 more 

次取得しています簡単なプログラムをしながら春を使用して、いくつかのプログラムをしようとは、これが私のSpring.xmlファイルです

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" 
"http://www.springframework.org/dtd/spring-beans-2.0.dtd"> 

<beans> 
    <bean id="t" class="beans.Test"> 
    <property name="driver" value="com.mysql.jdbc.Driver"/> 
    <property name="url" value="jdbc:mysql://localhost/emp"/> 
    <property name="user" value="root"/> 
    <property name="password" value="root123"/> 
    </bean> 
</beans> 

Test.java

package beans; 

import java.sql.Connection; 
import java.sql.DriverManager; 
import java.sql.PreparedStatement; 

import org.springframework.beans.factory.DisposableBean; 
import org.springframework.beans.factory.InitializingBean; 

public class Test implements InitializingBean, DisposableBean 
{ 
    private String driver,url,user,password; 
    private Connection con; 

    public void setDriver(String driver) { 
    this.driver = driver; 
} 
    public void setUrl(String url) { 
    this.url = url; 
} 
    public void setUser(String user) { 
    this.user = user; 
} 
    public void setPassword(String password) { 
    this.password = password; 
} 

    @Override 
public void afterPropertiesSet() throws Exception 
    { 
     Class.forName(driver); 
     con= DriverManager.getConnection(url, user, password); 
     System.out.println("Connection Opened"); 
    } 

    public void insert(int id,int age, String first, String last)throws Exception 
    { 
     PreparedStatement ps=con.prepareStatement("insert into employee vvalues(?,?,?,?)"); 
     ps.setInt(1, id); 
     ps.setInt(2, age); 
     ps.setString(3, first); 
     ps.setString(4, last); 
     ps.executeUpdate(); 
     System.out.println("Successfully Inserted"); 

    } 

    @Override 
    public void destroy() throws Exception 
    { 
     con.close(); 
     System.out.println("Connection Closed"); 
    } 

} 

メイン()

package test; 

import org.springframework.context.ConfigurableApplicationContext; 
import org.springframework.context.support.ClassPathXmlApplicationContext; 

public class Client 
{ 
public static void main(String[] args) 
    { 
    ConfigurableApplicationContext cap=new ClassPathXmlApplicationContext("resources/spring.xml"); 

    } 

} 

この原因は何ですか?

私はEclipse Oxygenを使用しています。これは基本的に、SpringのライフサイクルプロパティをテストしようとしているJDBCの概念を使用しています。

答えて

1

プロパティのゲッターが必要なように見えます。ドライバDoes the parameter type of the setter match the return type of the getter?

は、他の特性のために同じ

public String getDriver() { 
    return driver; 
} 

を追加します。

関連する問題