我有一个应用程序,使用MySQL和通过REST,Neo4j服务器版本执行一些批处理作业.
我无法弄清楚如何让它们正确地协同工作:我可以让它们同时工作,但不能同时工作.我发现的帖子并不是特定于Neo4j的服务器版本,也许这就是问题所在,因为其他一切对我来说都没问题.
我的配置:
JpaConfig
@Configuration
@EnableTransactionManagement(order=Ordered.HIGHEST_PRECEDENCE)
@PropertySource("META-INF/database.properties")
@ImportResource("classpath*:META-INF/repository.xml")
public class JpaConfig {
@Autowired
Environment env;
@Bean(destroyMethod = "close")
public DataSource dataSource() {
DataSource dataSource = new DataSource();
dataSource.setDriverClassName(env.getProperty("database.driverClassName"));
dataSource.setUrl(env.getProperty("database.url"));
dataSource.setUsername(env.getProperty("database.username"));
dataSource.setPassword(env.getProperty("database.password"));
dataSource.setTestOnBorrow(true);
dataSource.setTestOnReturn(true);
dataSource.setTestWhileIdle(true);
dataSource.setTimeBetweenEvictionRunsMillis(1800000);
dataSource.setNumTestsPerEvictionRun(3);
dataSource.setMinEvictableIdleTimeMillis(1800000);
dataSource.setValidationQuery("SELECT 1");
return dataSource;
}
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean entityManagerFactory = new LocalContainerEntityManagerFactoryBean();
entityManagerFactory.setDataSource(dataSource());
entityManagerFactory.setPackagesToScan("it.smartblue.mcba.domain");
entityManagerFactory.setJpaDialect(new HibernateJpaDialect());
Map<String, String> jpaProperties = new HashMap<>();
jpaProperties.put("hibernate.connection.charSet", "UTF-8");
jpaProperties.put("hibernate.ejb.naming_strategy", "org.hibernate.cfg.EJB3NamingStrategy");
jpaProperties.put("hibernate.bytecode.provider", "javassist");
jpaProperties.put("hibernate.dialect", "org.hibernate.dialect.MySQL5InnoDBDialect");
entityManagerFactory.setJpaPropertyMap(jpaProperties);
entityManagerFactory.setPersistenceProvider(new HibernatePersistence());
return entityManagerFactory;
}
@Bean
public PlatformTransactionManager transactionManager() …
Run Code Online (Sandbox Code Playgroud) 这基本上不是HashMap
基于键的排序方式.为此,我可以直接使用TreeMap
没有眨眼:)
我现在拥有的是
Map<String, Object> favoritesMap = new HashMap<String, Object>();
and its contents can be
["Wednesdays" : "abcd"]
["Mondays" : "1234"]
["Not Categorized" : "pqrs"]
["Tuesdays" : "5678"]
Run Code Online (Sandbox Code Playgroud)
我想基于键对HashMap进行排序,除此之外,我需要"未分类"才能找到最后一个.
因此,在迭代keySet时所期望的是
["Mondays", "Tuesdays", "Wednesdays", "Not Categorized"] i.e. sorted on keys and "Not Categorized" is the last one
Run Code Online (Sandbox Code Playgroud)
想HashMap
在创建时加入,["Not Categorized" : "pqrs"]
但最后添加但HashMap
不保证顺序:)
解决方案的任何其他指针?
我有一些方法,诸如简单的数组类Add(int n)
,AddAt(int n, int index)
等.
addAt方法从超类调用另一个方法
public void addAt(int n, int index) {
if (checkIndex(index, size + 1)){
...
}
}
Run Code Online (Sandbox Code Playgroud)
检查插入的索引是否不受限制,如果是,超类方法会向控制台输出错误消息.
如果邮件被打印,我应该如何测试?我正在使用JUnit4.12-beta
JUnit 3,JUnit 4,硒中的TestNG在这三个测试框架中如何以不同的方式实现硒的区别是什么?
任何人都可以清楚地解释..
提前致谢..
我正在使用Bitnami Tomcat堆栈上的Java servlet 实现JSON补丁规范.在servlet端,我通过重写HttpServlet.service()方法来处理HTTP PATCH方法,如下所示:
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
if (request.getMethod().equals("PATCH"))
doPatch(request, response);
else
super.service(request, response);
}
Run Code Online (Sandbox Code Playgroud)
问题是,当我尝试向Tomcat发送HTTP PATCH请求时,Apache httpd使用501"Method Not Implemented"拒绝它.
有没有办法让Apache httpd停止这样做?
我正在尝试编写一个程序,它采用不同形状的地毯,并创建一个地毯对象,其中包含在子类中定义的某些变量.我的代码是
public abstract class Carpet{
protected int area = 0;
protected double unitPrice = 0;
protected double totalPrice = 0.0;
protected String carpetID;
public Carpet(String id, double thisPrice){
carpetID = id;
unitPrice = thisPrice;
}
public String getCarpetId(){
return carpetID;
}
public String toString(){
String carpet = new String("\n" + "The CarpetId:\t\t" + getCarpetId() + "\nThe Area:\t\t" + area + "\nThe Unit Price\t\t" + unitPrice + "\nThe Total Price\t" + totalPrice + "\n\n");
return carpet;
}
public abstract void computeTotalPrice(); …
Run Code Online (Sandbox Code Playgroud) 我被告知以下代码不遵循正确的getter和setter约定.我很难知道为什么或在哪里.我正在使用构造函数将新的团队名称传递给set方法.我是Java的初学者,但我认为getter和setter方法似乎都很好.我错了吗?谢谢.
public class Team {
private String teamName;
public Team(String newName) {
setName(newName);
}
public String getName() {
return teamName;
}
public void setName(String newName) {
teamName = newName;
}
public String toString() {
return teamName;
}
public boolean equals(Team t){
if(t.getName().equals(teamName)){
return true;
} else{
return false;
}
}
}
Run Code Online (Sandbox Code Playgroud) 即时通讯使用arraylist填充微调器,并且arraylist actully持有已存储的android应用程序数据的文件中的数据为t =我的应用程序,我粘贴代码,问题是微调器填充但值出现两次
String[] wee = list2.toArray(new String[list2.size()]);
final String[] str={"Report 1","Report 2","Report 3","Report 4","Report 5"};
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(
this, android.R.layout.simple_spinner_item);
spinnerArrayAdapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item );
for(int i = 0;i < wee.length; i++){
spinnerArrayAdapter.add(wee[i]+"\n");
spinnerArrayAdapter.notifyDataSetChanged();
}
// Spinner spinYear = (Spinner)findViewById(R.id.spin);
spin.setAdapter(spinnerArrayAdapter);
Run Code Online (Sandbox Code Playgroud) 我想编写一个Java中的Hook,如果Liferay 5.2.3 Portal的会话超时则执行该Hook.
我设法编写了一个Hook,只要用户点击注销链接,就会执行以下设置liferay-hook.xml
:
<hook>
<event>
<event-class>com.extensions.hooks.LogoutHook</event-class>
<event-type>logout.events.pre</event-type>
</event>
</hook>
Run Code Online (Sandbox Code Playgroud)
但是,如果会话超时,则不会调用Logout Hook,但我需要在超时时执行相同的方法.我没有找到会话超时的事件类型.
有没有办法在会话超时时执行Java方法并识别结束会话的用户ID?
我看到这contentEquals
对于比较char序列很有用,但是我找不到任何地方指定比较两个字符串时最适合使用的方法。
这里提到了这两种方法之间的区别,但是没有明确说明如何处理两个字符串。
我可以看到usng的一个优点contentEquals
是,如果传入的变量的类型发生了更改,则将引发编译错误。缺点可能是执行速度快。
contentEquals
在比较字符串时我应该总是使用还是仅在有不同对象扩展时才使用它CharSequence
?