据我所知,从Java文件中读取基于字符的数据的两种最常用的方法是使用Scanner或BufferedReader.我也知道BufferedReader通过使用缓冲区来有效地读取文件以避免物理磁盘操作.我的问题是:
Scanner执行以及BufferedReader?Scanner,BufferedReader反之亦然?从同一个bean的另一个方法调用缓存方法时,Spring缓存不起作用.
这是一个以清晰的方式解释我的问题的例子.
组态:
<cache:annotation-driven cache-manager="myCacheManager" />
<bean id="myCacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
<property name="cacheManager" ref="myCache" />
</bean>
<!-- Ehcache library setup -->
<bean id="myCache"
class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" p:shared="true">
<property name="configLocation" value="classpath:ehcache.xml"></property>
</bean>
<cache name="employeeData" maxElementsInMemory="100"/>
Run Code Online (Sandbox Code Playgroud)
缓存服务:
@Named("aService")
public class AService {
@Cacheable("employeeData")
public List<EmployeeData> getEmployeeData(Date date){
..println("Cache is not being used");
...
}
public List<EmployeeEnrichedData> getEmployeeEnrichedData(Date date){
List<EmployeeData> employeeData = getEmployeeData(date);
...
}
}
Run Code Online (Sandbox Code Playgroud)
结果:
aService.getEmployeeData(someDate);
output: Cache is not being used
aService.getEmployeeData(someDate);
output:
aService.getEmployeeEnrichedData(someDate);
output: Cache is not being used
Run Code Online (Sandbox Code Playgroud)
该getEmployeeData方法调用使用缓存employeeData …
我想用JSR-303做一点自定义验证javax.validation.
我有一个领域.如果在此字段中输入了某个值,我想要求其他几个字段不是null.
我想弄清楚这一点.不确定我会称之为什么来帮助找到解释.
任何帮助,将不胜感激.我对此很新.
目前我正在考虑自定义约束.但我不确定如何从注释中测试依赖字段的值.基本上我不确定如何从注释访问面板对象.
public class StatusValidator implements ConstraintValidator<NotNull, String> {
@Override
public void initialize(NotNull constraintAnnotation) {}
@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
if ("Canceled".equals(panel.status.getValue())) {
if (value != null) {
return true;
}
} else {
return false;
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是panel.status.getValue();给我带来麻烦..不知道如何实现这一目标.
在我的SQL Server 2000数据库中,我有一个DATETIME名为lastTouchedset 的类型的时间戳(在函数中不在数据类型中)列getdate()作为其默认值/ binding.
我正在使用Netbeans 6.5生成的JPA实体类,并在我的代码中使用它
@Basic(optional = false)
@Column(name = "LastTouched")
@Temporal(TemporalType.TIMESTAMP)
private Date lastTouched;
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试将对象放入数据库时,我得到了,
javax.persistence.PersistenceException: org.hibernate.PropertyValueException: not-null property references a null or transient value: com.generic.Stuff.lastTouched
Run Code Online (Sandbox Code Playgroud)
我已经尝试设置设置@Basic为(optional = true),但是抛出一个异常,说数据库不允许列的null值TIMESTAMP,它不是设计的.
ERROR JDBCExceptionReporter - Cannot insert the value NULL into column 'LastTouched', table 'DatabaseName.dbo.Stuff'; column does not allow nulls. INSERT fails.
Run Code Online (Sandbox Code Playgroud)
我以前在纯Hibernate中使用它,但我有意识切换到JPA并且不知道如何告诉它该列被假设在数据库端生成.请注意,我仍然使用Hibernate作为我的JPA持久层.
我正在尝试优化我的Rails应用程序中的一些数据库查询,我有几个让我难过.他们都IN在WHERE子句中使用an 并且都在进行全表扫描,即使适当的索引似乎已经到位.
例如:
SELECT `user_metrics`.* FROM `user_metrics` WHERE (`user_metrics`.user_id IN (N,N,N,N,N,N,N,N,N,N,N,N))
Run Code Online (Sandbox Code Playgroud)
执行全表扫描并EXPLAIN说:
select_type: simple
type: all
extra: using where
possible_keys: index_user_metrics_on_user_id (which is an index on the user_id column)
key: (none)
key_length: (none)
ref: (none)
rows: 208
Run Code Online (Sandbox Code Playgroud)
使用IN语句时是否未使用索引或我是否需要以不同方式执行某些操作?这里的查询是由Rails生成的,所以我可以重新审视我的关系是如何定义的,但我想我首先要从数据库级别的潜在修复开始.
我正在尝试@Cacheable从同一个类中调用一个方法:
@Cacheable(value = "defaultCache", key = "#id")
public Person findPerson(int id) {
return getSession().getPerson(id);
}
public List<Person> findPersons(int[] ids) {
List<Person> list = new ArrayList<Person>();
for (int id : ids) {
list.add(findPerson(id));
}
return list;
}
Run Code Online (Sandbox Code Playgroud)
并希望结果findPersons也被缓存,但@Cacheable注释被忽略,并且findPerson每次都执行方法.
我在这里做错了什么,或者这是有意的吗?
Tomcat 8.5,这将是默认的Spring Boot 1.4,(将在明天发布)支持http2.
如何http2在Spring Boot应用程序中启用?
这个错误来自哪里?我没有在任何地方使用ensureIndex或createIndex在我的Nodejs应用程序中.我正在使用纱线包经理.
这是我的代码 index.js
import express from 'express';
import path from 'path';
import bodyParser from 'body-parser';
import mongoose from 'mongoose';
import Promise from 'bluebird';
dotenv.config();
mongoose.Promise = Promise;
mongoose.connect('mongodb://localhost:27017/bookworm', { useNewUrlParser: true });
const app = express();
Run Code Online (Sandbox Code Playgroud) 在阅读有关内存一致性错误的Java文档时.我找到了与两个创造事件相关的点 - 在关系之前:
当一个语句调用时Thread.start(),与该语句有一个before-before关系的每个语句也与新线程执行的每个语句都有一个before-before关系.新线程可以看到导致创建新线程的代码的影响.
当一个线程终止并导致Thread.join()另一个线程返回时,终止
线程执行的所有语句
与成功连接后的所有语句都有一个before-before关系.现在,执行连接的线程可以看到线程中代码的效果.
我无法理解他们的意思.如果有人用一个简单的例子解释它会很棒.
我为春季3休息多部分文件上传做了一个POC.它的工作正常.但是,当我尝试与我的应用程序集成时,我面临着问题.
它抛出以下异常:
org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request;
nested exception is org.apache.commons.fileupload.FileUploadException:
the request was rejected because no multipart boundary was found**"
Run Code Online (Sandbox Code Playgroud)
如果我的代码的任何部分出错,请告诉我.
豆子:
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="order" value="1" />
<property name="mediaTypes">
<map>
<entry key="json" value="application/json" />
<entry key="xml" value="application/xml" />
<entry key="file" value="multipart/mixed" />
</map>
</property>
</bean>
<!-- multipart resolver -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- one of the properties available; the maximum file size in bytes -->
<property name="maxUploadSize" value="50000000" />
</bean>
Run Code Online (Sandbox Code Playgroud)
控制器:
@Controller
public class MultipleFilesRecieve { …Run Code Online (Sandbox Code Playgroud) java ×6
spring ×3
caching ×2
annotations ×1
database ×1
ehcache ×1
file-io ×1
file-upload ×1
haproxy ×1
http2 ×1
jpa ×1
mongodb ×1
mongoose ×1
mysql ×1
node.js ×1
optimization ×1
persistence ×1
rest ×1
spring-boot ×1
spring-cache ×1
spring-mvc ×1
sql ×1
timestamp ×1
tomcat ×1
validation ×1