小编Tre*_*vor的帖子

使用phonegap在后台执行javascript

我创建了一个需要每隔"X"分钟触发javascript事件的应用程序.我正在使用手机间隙构建在Android/iPhone/Blackberry上部署,但我当然卡住了,因为javascript计时器不会在后台触发(当他们最小化应用程序时).我想知道,当应用程序在后台运行时,phonegap是否具有某种触发javascript事件的能力.

或者有没有办法在这些主要手机上轻松实现这一目标?我只需要用手机中的地理位置信息发起ajax呼叫.

iphone android blackberry background-process dom-events

9
推荐指数
1
解决办法
6839
查看次数

Spring Boot Hibernate 5忽略@Table和@Column

这让我很生气.

我正在实现Spring Social,它要求你有一个名为的数据库表UserConnection(而不是使用使用下划线分隔这两个单词的标准命名约定).

因此,在我天真的世界观中,我认为通过指定@Table(name="UserConnection")...... 很容易解决,但不会,这太简单了.

注释被忽略,并创建表格user_connection,然后使Spring Social具有合适的效果.

请告诉我有一些简单的方法告诉我的Spring Boot应用程序只是命名一个表(及其相应的列)以使用驼峰式命名约定而不是标准约定.

java spring-social spring-boot hibernate-5.x

9
推荐指数
1
解决办法
3778
查看次数

Spring Scheduled Jobs在不同的池中执行3次

我有一个每小时运行的Spring @Scheduled作业,但我发现它实际上每小时运行3次.这是显示此问题的日志输出:

2013-05-06 12:00:27,656 [pool-2-thread-1] INFO  src.jobs.NotifyUsersWhenVideoAvailableJob - Emails sent from NotifyUsersWhenVideoAvailableJob: 1
2013-05-06 12:00:27,750 [pool-1-thread-1] INFO  src.jobs.NotifyUsersWhenVideoAvailableJob - Emails sent from NotifyUsersWhenVideoAvailableJob: 1
2013-05-06 12:00:27,796 [pool-4-thread-1] INFO  src.jobs.NotifyUsersWhenVideoAvailableJob - Emails sent from NotifyUsersWhenVideoAvailableJob: 1
Run Code Online (Sandbox Code Playgroud)

这显然非常烦人,因为每次运行此作业时都会发送同一封电子邮件的三个副本.

我正在使用Spring 3.1

这是我的配置:

WEB.XML

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  version="2.5">
  <display-name>site2</display-name>
  <description>Roo generated site2 application</description>
  <context-param>
    <param-name>defaultHtmlEscape</param-name>
    <param-value>true</param-value>
  </context-param>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath*:META-INF/spring/applicationContext*.xml</param-value>
  </context-param>
  <filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
  </filter>

  <filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <filter>
    <filter-name>CharacterEncodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>UTF-8</param-value>
    </init-param>
    <init-param>
      <param-name>forceEncoding</param-name> …
Run Code Online (Sandbox Code Playgroud)

java spring scheduled-tasks

7
推荐指数
1
解决办法
3811
查看次数

用Hibernate for User实现EAV模式 - >设置关系

我正在尝试使用Java/Spring MVC和Hibernate在我的Web应用程序中设置一个简单的EAV模式.我似乎无法弄清楚这种情况下hibernate XML设置背后的魔力.

我的数据库表"SETUP"有三列:

  • user_id(FK)
  • setup_item
  • setup_value

数据库组合键由user_id |组成 setup_item

这是Setup.java类:

public class Setup implements CommonFormElements, Serializable {
  private Map data = new HashMap();
  private String saveAction;
  private Integer speciesNamingList;
  private User user;

  Logger log = LoggerFactory.getLogger(Setup.class);

  public String getSaveAction() {
    return saveAction;
  }

  public void setSaveAction(String action) {
    this.saveAction = action;
  }

  public User getUser() {
    return user;
  }

  public void setUser(User user) {
    this.user = user;
  }

  public Integer getSpeciesNamingList() {
    return speciesNamingList;
  }

  public void setSpeciesNamingList(Integer …
Run Code Online (Sandbox Code Playgroud)

hibernate spring-mvc entity-attribute-value

6
推荐指数
1
解决办法
3248
查看次数

如何验证是否在被测系统上调用方法(不是模拟)

我正在尝试编写一个单元测试,需要确认是否调用了一个方法.我正在使用JUnit,Mockito和PowerMock.

public class Invoice
{

  protected void createInvoice()
  {
    // random stuff here
    markInvoiceAsBilled("57");
  }

  protected void markInvoiceAsBilled(String code)
  {
    // marked as billed
  } 
}

所以,这里我的系统正在测试中Invoice.我正在运行这个测试:

  public class InvoiceTest
  {
    @Test
    public void testInvoiceMarkedAsBilled()
    {
      Invoice sut = new Invoice();
      Invoice sutSpy = spy(sut);

      sut.createInvoice();

      // I want to verify that markInvoiceAsBilled() was called
    }
  }

这个例子只是一个实际代码看起来像的例子....

我的问题是mockito说你只能验证是否在模拟对象上调用了一个方法......但是我不想模拟这个对象,因为它是我测试的对象.我知道你可以监视你正在测试的对象,所以这就是我试过的:


  verify(sutSpy).markInvoiceAsBilled("57");

我想做的不可能吗?或者我只是以错误的方式去做?

感谢大家 :)

java junit mocking powermock

6
推荐指数
1
解决办法
3688
查看次数

Favicon 未正确呈现,看起来乱码

我的网站图标似乎突然出现了问题。我不确定我做了什么改变导致它开始失败,但它曾经渲染得很好,现在它是乱码。

这是它的外观示例:

在此处输入图片说明

我正在使用 Spring Boot 并在谷歌上搜索有关如何让您的网站图标显示的所有典型答案......但我没有运气。

我注意到的一件事(不确定这是否正常)是,当我访问网站图标 URL 时,它不会将其作为图标加载到浏览器中,而是作为一堆文本加载。

这是我访问我的 localhost:8080/favicon.ico url 时发生的情况:

在此处输入图片说明

我能想到的唯一可能对 favicon 产生影响的最近更改是我的 WebSecurityConfig.java...我添加了一个 REALM 和基本身份验证。

这是 WebSecurityConfig.java 文件:

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter
{
  @Autowired
  private UserDetailsService userDetailsService;

  private static String REALM="MY_TEST_REALM";

  @Bean
  public PasswordEncoder passwordEncoder() {
      return new BCryptPasswordEncoder();
  }

  @Autowired
  public void globalSecurity (AuthenticationManagerBuilder auth) throws Exception
  {
    auth.userDetailsService(userDetailsService)
      .passwordEncoder(passwordEncoder());
  }

  @Override
  protected void configure(HttpSecurity http) throws Exception
  {
    // authenticate / authorize
    // authentication = who the hell are you? i.e. …
Run Code Online (Sandbox Code Playgroud)

favicon spring-boot

5
推荐指数
1
解决办法
578
查看次数

为什么在使用SpringJUnit4ClassRunner/MySQL/Spring/Hibernate时事务没有回滚

我正在进行单元测试,我希望所有提交给MySQL数据库的数据都将被回滚......但事实并非如此.即使我的日志显示正在发生回滚,也会提交数据.我已经和它摔跤了几天,所以我的设置已经改变了很多,这是我目前的设置.

LoginDAOTest.java:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"file:web/WEB-INF/applicationContext-test.xml", "file:web/WEB-INF/dispatcher-servlet-test.xml"})
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
public class UserServiceTest {

  private UserService userService;

  @Test
  public void should_return_true_when_user_is_logged_in ()
          throws Exception
  {
    String[] usernames = {"a","b","c","d"};

    for (String username : usernames)
    {
      userService.logUserIn(username);
      assertThat(userService.isUserLoggedIn(username), is(equalTo(true)));
    }
  }
Run Code Online (Sandbox Code Playgroud)

ApplicationContext的-Text.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:p="http://www.springframework.org/schema/p"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

  <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
          <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
          <property name="url" value="jdbc:mysql://localhost:3306/******"/>
          <property name="username" value="*****"/>
          <property name="password" value="*****"/>
  </bean>

  <tx:annotation-driven transaction-manager="transactionManager"/>

  <bean id="userService" class="Service.UserService">
    <property …
Run Code Online (Sandbox Code Playgroud)

mysql hibernate spring-mvc rollback junit4

4
推荐指数
2
解决办法
1万
查看次数

我想在Collection with Streams中计算集合中的集合数

假设我有一个SchoolDistrict,有许多Schools,有许多Students有很多Classes.

我想计算给予SchoolDistrict的课程数量.

Java 7的方式是这样的:

Integer classCount = 0;
for (School school : schoolDistrict)
{
    for (Student student : school.getStudents())
    {
        classCount += student.getClasses().size();
    }
}
Run Code Online (Sandbox Code Playgroud)

我知道Java 8带来的流应该会使这种事情在眼睛上变得容易一些.

但我无法弄清楚如何去做.

任何接受者?

编辑:有人将此标记为此帖的副本,我不相信这是因为该示例仅深入2级(国家/地区).我的问题涉及一个深入四个层次的问题(SchoolDistricts to Schools to Students to Classes)

java java-8 java-stream

2
推荐指数
1
解决办法
342
查看次数