我需要@Value
在类的实例变量中使用注入参数,并且可以在其所有子类中重用该变量.
@Value(server.environment)
public String environment;
public String fileName = environment + "SomeFileName.xls";
Run Code Online (Sandbox Code Playgroud)
这里的问题是fileName首先初始化然后发生环境注入.所以我总是得到null-SomeFileName.xls.
无论如何要@Value
在春天首先进行初始化.
我正在进行独立弹簧批量作业.在JUNIT中,这完全正常
@RunWith(SpringJUnit4ClassRunner.class)
//@SpringApplicationConfiguration(classes = KPBootApplication.class)
@ContextConfiguration(locations={"classpath:kp-sb.xml"})
public class KPBootApplicationTests {
private final static Logger LOG=LoggerFactory.getLogger(KPBootApplicationTests.class);
@Autowired
ApplicationContext context;
@Autowired
private JobLauncher jobLauncher;
@Autowired
private Job job;
@Test
public void testJob() {
final JobParameters jobParameters = new JobParametersBuilder()
.toJobParameters();
JobExecution execution;
try {
execution = jobLauncher.run(job, jobParameters);
final ExitStatus status = execution.getExitStatus();
if (ExitStatus.COMPLETED.getExitCode().equals(status.getExitCode())) {
LOG.info("Job completed Yeaaaaaaaa!!!!!");
} else {
final List<Throwable> exceptions = execution
.getAllFailureExceptions();
for (final Throwable throwable : exceptions) {
LOG.error(throwable.getMessage(), throwable);
}
}
} catch (JobExecutionAlreadyRunningException …
Run Code Online (Sandbox Code Playgroud) 我想通过内容过滤记录来自某个特定端点的所有传入请求和响应.即,当我有这样的要求时:
<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope">
<soap:Body>
<m:ProcessPhoto xmlns:m="http://www.w3schools.com/photos">
<m:Name>Apples</m:Name>
<m:Description>Photo with some apples in it</m:Description>
<!-- large encoded binary below -->
<m:Photo>anVzdCBhIHJhbmRvbSB0ZXh0DQpqdXN0IGEgcmFuZG9tIHRleHQNCmp1c3QgYSByYW5kb20gdGV4dA0KanVzdCBhIHJhbmRvbSB0ZXh0DQpqdXN0IGEgcmFuZG9tIHRleHQNCmp1c3QgYSByYW5kb20gdGV4dA0KanVzdCBhIHJhbmRvbSB0ZXh0DQp3b3csIGkgZGlkbid0IHRob3VnaHQgdGhhdCBhbnlvbmUgd291bGQgYmUgaW50ZXJlc3RlZCBpbiBkZWNvZGluZyB0aGlzLiBjb25ncmF0cyE=</m:Photo>
</m:ProcessPhoto>
</soap:Body>
</soap:Envelope>
Run Code Online (Sandbox Code Playgroud)
我想过滤它,以便它看起来像这样的日志
<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope">
<soap:Body>
<m:ProcessPhoto xmlns:m="http://www.w3schools.com/photos">
<m:Name>Apples</m:Name>
<m:Description>Photo with some apples in it</m:Description>
<m:Photo>hidden</m:Photo>
</m:ProcessPhoto>
</soap:Body>
</soap:Envelope>
Run Code Online (Sandbox Code Playgroud)
或完全删除m:照片元素.
我发现CXF有一些LoggingInInterceptor和LoggingOutInterceptor,我可以编写自己的拦截器来做到这一点.然而,这将是一项工作要做,所以我的问题是:你知道更好,开箱即用的解决方案吗?
我正在尝试在mybatis中生成如下所示的sql.
SELECT COL_C
FROM TBLE_1
WHERE (COL_A, COL_B) in ( ('kp','kar'),('srt','sach'));
Run Code Online (Sandbox Code Playgroud)
我的输入参数类型是HashMap.现在如何从mapper xml文件生成SQL.下面的代码抛出异常,说map被评估为null.
<select id="selectCOLC" parameterType="java.util.HashMap" resultType="String">
SELECT COL_C
FROM TBLE_1
WHERE (COL_A, COL_B) in
<foreach item="item" collection="#{map.keySet()}" open="((" separator="),(" close="))">
#{item},#{item.get(item)}
</foreach>
</select>
Run Code Online (Sandbox Code Playgroud)
其中的另一种方法是创建具有关键值字段类,创建对象的列表,然后通过parameterType
为list
它看起来像下面.
<select id="selectCOLC" parameterType="list" resultType="String">
SELECT COL_C
FROM TBLE_1
WHERE (COL_A, COL_B) in
<foreach item="item" collection="list" open="((" separator="),(" close="))">
#{item.getKey()},#{item.getVal()}
</foreach>
</select>
Run Code Online (Sandbox Code Playgroud)
但有没有办法让我的mapper工作第一种方法?除了将查询更改为union之外
我正在尝试将日期时间字符串解析为LocalDateTime.但是,如果我发送所有大写月份的一个错误,是否有任何解决方法.这是下面的代码
@Test
public void testDateFormat(){
DateTimeFormatter formatter= DateTimeFormatter.ofPattern("dd-MMM-yyyy HH:mm:ss");
LocalDateTime dateTime = LocalDateTime.parse("04-NOV-2015 16:00:00", formatter); //if I send month Nov it works
System.out.println(dateTime.getYear());
}
Run Code Online (Sandbox Code Playgroud)
同样适用于simpleDateFormat
@Test
public void testSimpleDateTime() throws ParseException{
SimpleDateFormat format = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
Date dateTime = format.parse("04-NOV-2015 16:00:00");
System.out.println(dateTime.getTime());
}
Run Code Online (Sandbox Code Playgroud) 是否可以从xsd文件生成具有Claendar类型字段的实体?我正在尝试xs:date和xs:dateTime但仍然获得XMLGregarionCalendar.我正在使用cxf-codegen-plugin和jaxb bninding.谢谢.保罗.
如何重试方法调用程序任务,我知道如果一个块任务失败,可以选择重试,并且可以选择设置退避策略,但是在方法调用程序任务xsd中我找不到重试选项.在发生故障时是否还有其他替代方法可以重试任务.
我正在尝试使用所有常见的 spring jar 来设置 tomcat 服务器,这些 spring jar 将转到 tomcat lib 目录,因为我有许多使用 spring 的 Web 应用程序。然而,我的一个网络应用程序也使用带有石英罐的弹簧批次。当所有 jars 都在 app1/WEB-INF/lib 目录中时,这个网络应用程序运行良好。但是,当我尝试将所有常见的 spring jar 移动到 app1/WEB_INF/lib 中的 tomcat/lib 目录和 spring batch 和 quartaz jar 时,我收到 noclassdefFound 错误。这是堆栈跟踪
Caused by: java.lang.NoClassDefFoundError: org/quartz/ObjectAlreadyExistsException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
at java.lang.Class.getDeclaredConstructors(Class.java:1836)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:230)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:972)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:945)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getSingletonFactoryBeanForTypeCheck(AbstractAutowireCapableBeanFactory.java:777)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryBean(AbstractAutowireCapableBeanFactory.java:707)
at org.springframework.beans.factory.support.AbstractBeanFactory.isTypeMatch(AbstractBeanFactory.java:523)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:357)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:335)
at org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors(BeanFactoryUtils.java:187)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:895)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:853)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:768)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:486)
... 60 more
Caused by: java.lang.ClassNotFoundException: org.quartz.ObjectAlreadyExistsException
at …
Run Code Online (Sandbox Code Playgroud) 在阅读了很少有关交易的文件后,我现在完全糊涂了.我先解释一下我的情景.
我有一个批量读取,大约需要3分钟从表中读取数据(SELECT)查询.同时另一个线程尝试执行INSERT/UPDATE/DELETE.它抛出一个错误,说" 无法获取事务 "(因为我的数据源的默认事务为8(SERIALIZABLE)).
要允许INSERT/UPDATE/DELETE执行,我将事务设置为READ_UNCOMMITTED(根本没有锁定(读/写/范围)).但是,当我执行我的程序时,它抛出一个错误,说唯一支持的事务是READ_COMMITTED和SERIALIZABLE.
当我进一步调查,我发现了甲骨文公司推出的事务隔离型快照隔离这无形中消除重复读取和脏采取读快照给予一致的数据事务期间的数据库,在那里.
从上面的语句我可以使用READ_COMMITTED的事务类型,但是维基百科到目前为止完全混淆了我的理解与下面的陈述:
快照隔离在Oracle [2] [3] [4]和9.1之前的PostgreSQL版本中被称为"可序列化"模式[5] [6] [7],这可能会导致与"真正的可串行化"模式混淆.赞成和反对这一决定都有争议; 很清楚的是,用户必须意识到这一区别,以避免在他们的数据库系统逻辑中出现可能不希望的异常行为.
所以现在我的问题是:
我想使用mybatis来修复字符串列表.我正在使用以下代码,但是如下所示获取illegalArgument异常:
javax.servlet.ServletException: org.mybatis.spring.MyBatisSystemException: SqlSession operation; nested exception is java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for java.lang.Object.toString
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:515)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419)
Run Code Online (Sandbox Code Playgroud)
Mybatis配置:
<select id="fetchIds" resultType="java.lang.String" >
SELECT distinct ids
FROM abc.emp
</select>
Run Code Online (Sandbox Code Playgroud)
我的道法是:
@Override
public List<String> fetchIds() {
System.out.println("Inside fetchIds");
SqlSession session = null;
List retrieveList = null;
try{
session = sqlSessionFactory.openSession();
System.out.println("After session creation:"+session);
retrieveList = session.selectList("fetchIds");
}finally{
session.close();
}
return retrieveList;
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以建议我们如何实现这一目标.
在tomcat服务器sartup完成后,是否存在spring或tomcat中的任何机制,生命周期事件或回调(我已经配置了8个Web应用程序和队列,我希望在启动所有应用程序后将通知返回给每个应用程序.) .我知道spring有应用程序监听器,可以在初始化Web应用程序后使用.但我不能在我的情况下使用它,因为我希望在初始化所有Web应用程序后收到通知.
**已编辑***
我添加了实现tomcat的监听器来记录消息.但我绝对不知道在哪里挂钩这个听众.
我尝试使用spring创建这个bean,并且通过向web.xml添加监听器两者都不起作用.
这是我的代码
public class KPTomcatListener implements LifecycleListener {
private static final Logger LOG = LoggerFactory.getLogger(KPTomcatListener.class);
/**
* All the events of tomcat
* AFTER_START_EVENT,
* AFTER_STOP_EVENT,
* BEFORE_START_EVENT,
* BEFORE_STOP_EVENT,
* DESTROY_EVENT,
* INIT_EVENT,
* PERIODIC_EVENT,
* START_EVENT,
* STOP_EVENT
*/
private static int counter;
@Override
public void lifecycleEvent(LifecycleEvent arg0) {
String event = arg0.getType();
LOG.debug("Tomcat Envents: " + (++counter) + " :: " + event);
if(event.equals("AFTER_START_EVENT")) {
LOG.debug("Hey I've started");
}
}
}
Run Code Online (Sandbox Code Playgroud) 我写了以下多线程程序.我想取消所有线程,如果其中一个线程发回false作为返回.但是,虽然我通过取消单个任务取消了该线程.它不起作用.为了取消线程我需要做些什么改变?
我写了以下多线程程序.我想取消所有线程,如果其中一个线程发回false作为返回.但是,虽然我通过取消单个任务取消了该线程.它不起作用.为了取消线程我需要做些什么改变?
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.Callable;
public class BeamWorkerThread implements Callable<Boolean> {
private List<BeamData> beamData;
private String threadId;
public BeamScallopingWorkerThread(
List<BeamData> beamData, String threadId) {
super();
this.beamData = beamData;
this.threadId = threadId;
}
@Override
public Boolean call() throws Exception {
Boolean result = true;
DataValidator validator = new DataValidator();
Iterator<BeamScallopingData> it = beamData.iterator();
BeamData data = null;
while(it.hasNext()){
data = it.next();
if(!validator.validateDensity(data.getBin_ll_lat(), data.getBin_ll_lon(), data.getBin_ur_lat(), data.getBin_ur_lon())){
result = false;
break;
}
}
return result;
}
}
ExecutorService threadPool = …
Run Code Online (Sandbox Code Playgroud) 请问这个设置有什么明显的错误吗?在应用程序启动时,我得到属性“命名空间”必须为元素类型“映射器”声明,当它明确声明时。
spring xml资源dao.xml:
<?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:util="http://www.springframework.org/schema/util"
xmlns:jms="http://www.springframework.org/schema/jms"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.2.xsd
http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-2.5.xsd">
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/JNDINAME"/>
<property name="lookupOnStartup" value="true"/>
<property name="cache" value="true"/>
<property name="proxyInterface" value="javax.sql.DataSource"/>
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="mapperScanner" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.mycompany.dao"/>
<property name="sqlSessionFactory" ref="sqlSessionFactory"/>
</bean>
</beans>
Run Code Online (Sandbox Code Playgroud)
界面:
public interface MyDAO {
public void save(@Param("id") String id);
}
Run Code Online (Sandbox Code Playgroud)
映射器xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<mapper namespace="com.mycompany.dao">
<typeAlias alias="xxxVO" …
Run Code Online (Sandbox Code Playgroud)