- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 spring DAO 和 spring JDBC 模板的新手,在下面的代码中,我在 JDBC 模板中得到 null,并且我检查了一些示例,并且我的代码中的一切看起来都很好。如果我错过了什么,请告诉我
类代码:
import com.bnym.repo.rule.Deal;
import com.bnym.repo.rule.Security;
@Repository
public class Test {
@Resource(name = "jdbcTemplate")
private JdbcTemplate jdbcTemplate;
@Resource(name = "namedParameterJdbcTemplate")
private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
Deal deal= new Deal();
public static void main(String[] args) {
Security sec1 = new Security();
Set<String> sec1Index = new HashSet<String>();
sec1Index.add("NP");
sec1.setSecurityCategory("Fixed Income");
sec1.setBroadType("sdsdfs");
sec1.setCountry("fsdf");
sec1.setCurrency("AUD");
sec1.setIndex(sec1Index);
sec1.setIssuerGroup("AAAAA");
sec1.setIssuerName("issuerName");
sec1.setIssuerRating(10);
sec1.setIssueSize(111111);
sec1.setMarketCap(11111);
sec1.setMonthsToMaturity(10);
sec1.setRepoSecurityID("111");
sec1.setRepoSecurityIdType("repoSecurityIdType");
sec1.setSecurityPrice(22222222);
sec1.setSecurityRating(88);
sec1.setSecuritySubType("Stripped Government Bond");
sec1.setTaxDocReceived(true);
sec1.setUnratedSecurities(false);
Security sec2 = new Security();
sec2.setSecurityCategory("dasdas");
sec2.setBroadType("Bond");
sec2.setCountry("Japan");
sec2.setCurrency("AUD");
Set<String> sec2Index = new HashSet<String>();
sec2Index.add("NP");
sec2.setIndex(sec2Index);
sec2.setIssuerGroup("AAAAA");
sec2.setIssuerName("issuerName");
sec2.setIssuerRating(10);
sec2.setIssueSize(111111);
sec2.setMarketCap(11111);
sec2.setMonthsToMaturity(10);
sec2.setRepoSecurityID("222");
sec2.setRepoSecurityIdType("repoSecurityIdType");
sec2.setSecurityPrice(22222222);
sec2.setSecurityRating(10);
sec2.setSecuritySubType("Stripped Government Bond");
sec2.setTaxDocReceived(true);
sec2.setUnratedSecurities(false);
Security sec3 = new Security();
sec3.setSecurityCategory("dasdas");
sec3.setBroadType("Bond");
sec3.setCountry("Italy");
sec3.setCurrency("sdfsd");
Set<String> sec3Index = new HashSet<String>();
sec3Index.add("NP");
sec3.setIndex(sec3Index);
sec3.setIssuerGroup("AAAAA");
sec3.setIssuerName("issuerName");
sec3.setIssuerRating(10);
sec3.setIssueSize(111111);
sec3.setMarketCap(11111);
sec3.setMonthsToMaturity(10);
sec3.setRepoSecurityID("333");
sec3.setRepoSecurityIdType("repoSecurityIdType");
sec3.setSecurityPrice(22222222);
sec3.setSecurityRating(10);
sec3.setSecuritySubType("Stripped Government Bond");
sec3.setTaxDocReceived(true);
sec3.setUnratedSecurities(false);
Security sec4 = new Security();
sec4.setSecurityCategory("dasdas");
sec4.setBroadType("EQTY");
sec4.setCountry("Portugal");
sec4.setCurrency("sdfsd");
Set<String> sec4Index = new HashSet<String>();
sec4Index.add("NP");
sec4.setIndex(sec4Index);
sec4.setIssuerGroup("AAAAA");
sec4.setIssuerName("issuerName");
sec4.setIssuerRating(10);
sec4.setIssueSize(111111);
sec4.setMarketCap(11111);
sec4.setMonthsToMaturity(10);
sec4.setRepoSecurityID("444");
sec4.setRepoSecurityIdType("repoSecurityIdType");
sec4.setSecurityPrice(22222222);
sec4.setSecurityRating(10);
sec4.setSecuritySubType("Common Stock");
sec4.setTaxDocReceived(false);
sec4.setUnratedSecurities(false);
Security sec5 = new Security();
sec5.setSecurityCategory("Fixed Income");
sec5.setBroadType("sdsdfs");
sec5.setCountry("fsdf");
sec5.setCurrency("AUD");
Set<String> sec5Index = new HashSet<String>();
sec5Index.add("NP");
sec5.setIndex(sec5Index);
sec5.setIssuerGroup("Dexia SA");
sec5.setIssuerName("issuerName");
sec5.setIssuerRating(10);
sec5.setIssueSize(111111);
sec5.setMarketCap(11111);
sec5.setMonthsToMaturity(10);
sec5.setRepoSecurityID("555");
sec5.setRepoSecurityIdType("repoSecurityIdType");
sec5.setSecurityPrice(22222222);
sec5.setSecurityRating(88);
sec5.setSecuritySubType("Stripped Government Bond");
sec5.setTaxDocReceived(true);
sec5.setUnratedSecurities(false);
Security sec6 = new Security();
sec6.setSecurityCategory("dasdas");
sec6.setBroadType("Bond");
sec6.setCountry("dsds");
sec6.setCurrency("sdfsd");
Set<String> sec6Index = new HashSet<String>();
sec6Index.add("NP");
sec6.setIndex(sec6Index);
sec6.setIssuerGroup("AAAAA");
sec6.setIssuerName("issuerName");
sec6.setIssuerRating(10);
sec6.setIssueSize(111111);
sec6.setMarketCap(11111);
sec6.setMonthsToMaturity(10);
sec6.setRepoSecurityID("666");
sec6.setRepoSecurityIdType("repoSecurityIdType");
sec6.setSecurityPrice(22222222);
sec6.setSecurityRating(10);
sec6.setSecuritySubType("Supranational Bond");
sec6.setTaxDocReceived(true);
sec6.setUnratedSecurities(false);
Security sec7 = new Security();
sec7.setSecurityCategory("Equities");
sec7.setBroadType("EQTY");
sec7.setCountry("Australia");
sec7.setCurrency("AUD");
Set<String> sec7Index = new HashSet<String>();
sec7Index.add("S&P/ASX20");
sec7.setIndex(sec7Index);
sec7.setIssuerGroup("AAAAA");
sec7.setIssuerName("issuerName");
sec7.setIssuerRating(10);
sec7.setIssueSize(111111);
sec7.setMarketCap(11111);
sec7.setMonthsToMaturity(10);
sec7.setRepoSecurityID("777");
sec7.setRepoSecurityIdType("repoSecurityIdType");
sec7.setSecurityPrice(22222222);
sec7.setSecurityRating(10);
sec7.setSecuritySubType("Common Stock");
sec7.setTaxDocReceived(true);
sec7.setUnratedSecurities(false);
Security sec8 = new Security();
sec8.setSecurityCategory("Equities");
sec8.setBroadType("EQTY");
sec8.setCountry("Australia");
sec8.setCurrency("AUD");
Set<String> sec8Index = new HashSet<String>();
sec8Index.add("S&P/ASX20");
sec8.setIndex(sec8Index);
sec8.setIssuerGroup("AAAAA");
sec8.setIssuerName("issuerName");
sec8.setIssuerRating(10);
sec8.setIssueSize(111111);
sec8.setMarketCap(11111);
sec8.setMonthsToMaturity(10);
sec8.setRepoSecurityID("888");
sec8.setRepoSecurityIdType("repoSecurityIdType");
sec8.setSecurityPrice(22222222);
sec8.setSecurityRating(10);
sec8.setSecuritySubType("Common Stock");
sec8.setTaxDocReceived(true);
sec8.setUnratedSecurities(false);
List<Security> securities= new ArrayList<Security>();
securities.add(sec1);
securities.add(sec2);
securities.add(sec3);
securities.add(sec4);
securities.add(sec5);
securities.add(sec6);
securities.add(sec7);
securities.add(sec8);
Deal deal = new Deal();
Test t =new Test();
t.checkTaxRule(securities);
}
public List<Security> checkTaxRule(List<Security> securities){
int count= 0;
String reason="fail due to tax rule";
List<Security> passsecurities = null;
MapSqlParameterSource params = new MapSqlParameterSource();
List<Map<String,Object>> rows = null;
params.addValue("userId", "3h9author1");
final String query="SELECT * FROM T_ECT_USER WHERE USER_ID=:userId ";
rows = namedParameterJdbcTemplate.queryForList(query, params);
for(Security security: securities){
for(Map<String,Object> rule :rows){
if(security.getCountry()==rule.get("COUNTRY_CODE") && security.getSecuritySubType()==rule.get("SECURITY_SUBTYPE")){
deal.addEligibleSecurity(security, reason);
break;
}
else{
count++;
}
if(count==rows.size()){
deal.addNonEligibleSecurity(security, reason);
}
}
}
return null;
}
}
我将其作为 java 应用程序运行(作为 java 应用程序运行)
下面是配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sec="http://www.springframework.org/schema/security" xmlns:c="http://www.springframework.org/schema/c"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:ctx="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd ttp://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!-- property files -->
<ctx:property-placeholder location="classpath*:*.properties" />
<!-- database access -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driver}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${db.user}" />
<property name="password" value="${db.password}" />
</bean>
<bean id="pool" class="org.apache.commons.pool.impl.GenericObjectPool">
<property name="minEvictableIdleTimeMillis">
<value>300000</value>
</property>
<property name="timeBetweenEvictionRunsMillis">
<value>60000</value>
</property>
</bean>
<bean id="dsConnectionFactory" class="org.apache.commons.dbcp.DataSourceConnectionFactory">
<constructor-arg>
<ref bean="dataSource" />
</constructor-arg>
</bean>
<bean id="poolableConnectionFactory" class="org.apache.commons.dbcp.PoolableConnectionFactory">
<constructor-arg index="0">
<ref bean="dsConnectionFactory" />
</constructor-arg>
<constructor-arg index="1">
<ref bean="pool" />
</constructor-arg>
<constructor-arg index="2">
<null />
</constructor-arg>
<constructor-arg index="3">
<null />
</constructor-arg>
<!-- read only -->
<constructor-arg index="4">
<value>false</value>
</constructor-arg>
<!-- auto commit -->
<constructor-arg index="5">
<value>true</value>
</constructor-arg>
</bean>
<bean id="pooledDS" class="org.apache.commons.dbcp.PoolingDataSource" depends-on="poolableConnectionFactory">
<constructor-arg>
<ref bean="pool" />
</constructor-arg>
</bean>
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="namedParameterJdbcTemplate" class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
<constructor-arg index="0">
<ref bean="pooledDS" />
</constructor-arg>
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg index="0">
<ref bean="pooledDS" />
</constructor-arg>
</bean>
<bean id="commonDao" class="com.bnym.cm.common.dao.CommonDao" />
<bean id="idFactory" class="com.bnym.cm.common.impl.IdFactory" />
<bean id="exceptionHandler" class="com.bnym.cm.common.service.ExceptionHandler" />
<bean id="messageListener" class="com.bnym.cm.common.jms.CMMessageListener" />
<bean id="messageSender" class="com.bnym.cm.common.jms.CMMessageSender" />
<bean id="mqConnectionFactory" class="com.ibm.mq.jms.MQQueueConnectionFactory">
<property name="hostName" value="${jms.hostname.local}" />
<property name="port" value="${jms.port.local}" />
<property name="queueManager" value="${jms.queue.manager.local}" />
</bean>
<bean id="jmsQueueConnectionFactory" class="org.springframework.jms.connection.SingleConnectionFactory">
<property name="targetConnectionFactory" ref="mqConnectionFactory" />
</bean>
<bean id="jmsDestinationResolver" class="org.springframework.jms.support.destination.DynamicDestinationResolver" />
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="jmsQueueConnectionFactory" />
<property name="destinationResolver" ref="jmsDestinationResolver" />
<property name="defaultDestinationName" value="${jms.queue.rep.local}" />
<property name="pubSubDomain" value="false" />
<property name="receiveTimeout" value="20000" />
</bean>
<bean id="jmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="jmsQueueConnectionFactory"/>
<property name="destinationName" value="${jms.queue.esb.local}"/>
<property name="messageListener" ref="messageListener" />
</bean>
<beans profile="Dev">
<bean id="mqConnectionFactory" class="com.ibm.mq.jms.MQQueueConnectionFactory">
<property name="hostName" value="${jms.hostname.Dev}" />
<property name="port" value="${jms.port.Dev}" />
<property name="queueManager" value="${jms.queue.manager.Dev}" />
<property name="transportType" value="${jms.transport.type.Dev}" />
<property name="channel" value="${jms.client.channel.Dev}" />
</bean>
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="jmsQueueConnectionFactory" />
<property name="destinationResolver" ref="jmsDestinationResolver" />
<property name="defaultDestinationName" value="${jms.queue.rep.Dev}" />
<property name="pubSubDomain" value="false" />
<property name="receiveTimeout" value="20000" />
</bean>
<bean id="jmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="jmsQueueConnectionFactory"/>
<property name="destinationName" value="${jms.queue.esb.Dev}"/>
<property name="messageListener" ref="messageListener" />
</bean>
</beans>
<beans profile="QA">
<bean id="mqConnectionFactory" class="com.ibm.mq.jms.MQQueueConnectionFactory">
<property name="hostName" value="${jms.hostname.QA}" />
<property name="port" value="${jms.port.QA}" />
<property name="queueManager" value="${jms.queue.manager.QA}" />
<property name="transportType" value="${jms.transport.type.QA}" />
<property name="channel" value="${jms.client.channel.QA}" />
</bean>
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="jmsQueueConnectionFactory" />
<property name="destinationResolver" ref="jmsDestinationResolver" />
<property name="defaultDestinationName" value="${jms.queue.rep.QA}" />
<property name="pubSubDomain" value="false" />
<property name="receiveTimeout" value="20000" />
</bean>
<bean id="jmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="jmsQueueConnectionFactory"/>
<property name="destinationName" value="${jms.queue.esb.QA}"/>
<property name="messageListener" ref="messageListener" />
</bean>
</beans>
</beans>
namedParameterJdbcTemplate 为 null
最佳答案
您的 main 方法永远不会创建任何 Spring 上下文,并且不会从 Spring 上下文获取测试 bean。因此 Spring 无法神奇地知道您已经创建了一个测试实例并在其中注入(inject) JDBC 模板。
如果您使用
获取 Spring beannew Test()
正如您所做的那样,它不是 Spring bean。它只是 Spring 不知道的常规 Java 对象。
关于java - 使用注释的 Spring JDBC 模板为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29555079/
最近开始学习oracle和sql。 在学习的过程中,我遇到了几个问题,我的 friend 在接受采访时被问到这些问题。 SELECT * FROM Employees WHERE NULL IS N
这个问题在这里已经有了答案: Can we subtract NULL pointers? (4 个回答) 关闭 2 个月前。 是否定义了NULL - NULL? (char *)NULL - (ch
是否有推荐的方法(根据 .net Framework 指南)检查 null,例如: if (value == null) {//code1} else {//code2} 或 if (value !=
我正在尝试将值插入数据库,但出现这样的错误任何人都可以告诉我为什么该值为空,如下所示: An exception occurred while executing 'INSERT INTO perso
这个问题在这里已经有了答案: String concatenation with a null seems to nullify the entire string - is that desire
您好,我正在 Android 联系人搜索模块中工作。我正在查询下方运行。 cur = context.getContentResolver().query(ContactsContract.Data.
下面的 SQL 表定义说明了从我的 MYSQL 数据库创建表的语句之一,该数据库是由我公司的前开发人员开发的。 DROP TABLE IF EXISTS `classifieds`.`category
我主要有应用程序开发背景。在编程语言中 variable == null或 variable != null有效。 当涉及到 SQL 时,以下查询不会给出任何语法错误,但也不会返回正确的结果。 sel
我在尝试检查某些元素是否为 NULL 时遇到段错误或不。任何人都可以帮忙吗? void addEdge(int i, int j) { if (i >= 0 && j > 0)
在 SQL 服务器中考虑到以下事实:Col1 和 Col2 包含数值和 NULL 值 SELECT COALESCE(Col1,Col2) 返回一个错误:“COALESCE 的至少一个参数必须是一个不
在 SQL 服务器中考虑到以下事实:Col1 和 Col2 包含数值和 NULL 值 SELECT COALESCE(Col1,Col2) 返回一个错误:“COALESCE 的至少一个参数必须是一个不
下面查询的关系代数表达式是什么?我找不到“Is Null”的表达式。 SELECT reader.name FROM reader LEFT JOIN book_borrow ON reader.ca
我正在尝试使用三元运算符来检查值是否为 null 并返回一个表达式或另一个。将此合并到 LINQ 表达式时,我遇到的是 LINQ 表达式的 Transact-SQL 转换试图执行“column = n
我在给定的代码中看到了以下行: select(0, (fd_set *) NULL, (fd_set *) NULL, (fd_set *) NULL, &timeout); http://linux
var re = /null/g; re.test('null null'); //> true re.test('null null'); //> true re.test('null null')
这个问题在这里已经有了答案: 关闭 13 年前。 我今天避开了一场关于数据库中空值的激烈辩论。 我的观点是 null 是未指定值的极好指示符。团队中有意见的其他每个人都认为零和空字符串是可行的方法。
由于此错误,我无法在模拟器中运行我的应用: Error:null value in entry: streamOutputFolder=null 或 gradle - Error:null value
我正在尝试在 Android 应用程序中创建电影数据库,但它返回错误。知道这意味着什么吗? public Cursor returnData() { return db.query(TABLE
我一直在检查浏览器中的日期函数以及运行时间 new Date (null, null, null); 在开发工具控制台中,它给出了有效的日期 Chrome v 61 回归 Sun Dec 31 189
为什么 NA==NULL 会导致 logical (0) 而不是 FALSE? 为什么 NULL==NULL 会导致 logical(0) 而不是 TRUE? 最佳答案 NULL 是一个“零长度”对象
我是一名优秀的程序员,十分优秀!