Spring应用程序我试过setter注入它运行良好。当我编写构造函数注入时,它失败了。
public class Sample {
JdbcTemplate jdbcTemplate;
public Sample(){
}
public Sample(JdbcTemplate jdbcTemplate){
System.out.println("invoked");
this.jdbcTemplate=jdbcTemplate;
}
}
上下文文件
<bean id="derbyDataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${db.driver}" />
<property name="url"
value="jdbc:derby:#{systemProperties['user.appdata']}/${db.name};create=true" />
<property name="username" value="${db.user}" />
<property name="password" value="${db.password}" />
</bean>
<!-- JDBC Template Bean -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="derbyDataSource" />
</bean>
<bean id="sample" class="com.exbury.Sample">
<constructor-arg ref="jdbcTemplate"></constructor-arg>
</bean>
加载上下文
ApplicationContext context = new ClassPathXmlApplicationContext("derbyDatabaseConfiguration.xml");
错误
Exception in thread "main" java.lang.IncompatibleClassChangeError: class org.springframework.core.LocalVariableTableParameterNameDiscoverer$ParameterNameDiscoveringVisitor has interface org.springframework.asm.ClassVisitor as super class
答案 0 :(得分:0)
此Source解决了类似的错误。我不确定你的,但你可以尝试添加这个排除吗?
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>your version</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-asm</artifactId>
</exclusion>
</exclusions>
</dependency>