小编dde*_*zia的帖子

Gson - 无法解释的日期

我必须将Json对象与具有Date的java对象绑定.我的Json上的日期格式如下:

2013-01-04T10:50:26 + 0000

我正在使用GsonBulder如下:

Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").create();
Run Code Online (Sandbox Code Playgroud)

但我得到以下例外:

The RuntimeException could not be mapped to a response, re-throwing to the HTTP container
com.google.gson.JsonSyntaxException: 2013-01-04T10:50:26+0000
at com.google.gson.internal.bind.DateTypeAdapter.deserializeToDate(DateTypeAdapter.java:81)
.....
Caused by: java.text.ParseException: Unparseable date: "2013-01-04T10:50:26+0000"
at java.text.DateFormat.parse(DateFormat.java:337)
at com.google.gson.internal.bind.DateTypeAdapter.deserializeToDate(DateTypeAdapter.java:79)
Run Code Online (Sandbox Code Playgroud)

我正在尝试用Gson加载这个请求:

https://graph.facebook.com/me?fields=id,username,email,link,updated_time&access_token=accessToken
Run Code Online (Sandbox Code Playgroud)

而且回应是

{"id":"12345","username":"myusername","email":"myemail\u0040yahoo.it","link":"http:\/\/www.facebook.com\/mysusername","updated_time":"2013-01-04T10:50:26+0000"}
Run Code Online (Sandbox Code Playgroud)

java gson

24
推荐指数
1
解决办法
3万
查看次数

删除tomcat自动启动

当我运行ubuntu时,我安装的tomcat服务器自动运行,我必须手动关闭它.我希望tomcat不要在启动时自动启动.如何在启动时禁用tomcat的启动?

ubuntu tomcat autostart

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

Spring + JPA + MVC - 创建bean时出错

我在eclipse中开发了一个Spring JPA项目,可以访问存储在mysql服务器中的数据.现在我需要在Spring @ MVC项目中导入这个项目.所以

  • 我在JPA项目的构建路径中配置以导出maven依赖项
  • 我将项目添加到tomcat bootstrap类路径中,
  • 我将JPA/Spring项目添加到Spring @MVC项目的类路径中
  • 我还将jpa应用程序上下文添加到MVC项目的根上下文中.

当我尝试在tomcat服务器上运行应用程序时,我收到一个错误.我似乎缺少spring-beans库,但正如你在pom配置中看到的那样,我导入了它.这是错误日志:

INFO: Initializing Spring root WebApplicationContext
INFO : org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization started
INFO : org.springframework.web.context.support.XmlWebApplicationContext - Refreshing Root WebApplicationContext: startup date [Mon Feb 06 22:26:12 CET 2012]; root of context hierarchy
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/spring/root-context.xml]
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [META-INF/spring/app-context.xml]
INFO : org.springframework.context.annotation.ClassPathBeanDefinitionScanner - JSR-330 'javax.inject.Named' annotation found and supported for component …
Run Code Online (Sandbox Code Playgroud)

java spring jpa spring-mvc

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

使用Facebook Oauth从Web服务器上的移动应用程序登录流程

我有一个使用Spring和Spring安全性构建的Web应用程序,允许用户通过Facebbok注册ether或创建帐户,在这两种情况下都会创建一个Web应用程序帐户.所以2种注册方法如下::

  • 直接在Web应用程序上注册:用户名和密码存储在db中.
  • 通过Facebook注册:用户登录facebook(Outh),网络应用程序从Facebook检索数据以填写注册表单.Web应用程序提示用户创建Webapp帐户.在我的数据库中,我存储了web应用程序用户和facebook数据(访问令牌等),所以第二次尝试登录时我可以将facebook帐户与web app帐户相匹配(我使用spring social).

现在我正在为移动应用程序创建一个休息服务,它需要身份验证.我使用基本的http auth来访问Web服务.

我现在的问题是如何使用spring security在我的Web应用程序中登录用户?

我的想法是:

  • 移动应用程序登录到facebook并检索access_token(尚未与Web应用程序服务器联系)
  • 移动应用程序将访问令牌发送到Web应用程序
  • Web应用程序检查访问令牌是否与db有效,或直接与facebook
  • 如果访问令牌有效,应用程序会将用户名和密码(可以使用私钥算法加密)发送回移动应用程序.
  • 一旦收到Web应用程序用户和密码,用户就会被验证,并且此信息存储在移动设备上并用于http身份验证.

你认为这种流程是否安全?你有其他想法吗?

先感谢您

facebook login spring-security spring-social

7
推荐指数
0
解决办法
1042
查看次数

Terraform:创建 App Engine 应用程序时出错:googleapi:错误 403:调用方没有权限,禁止

我正在尝试使用 terraform 创建一个简单的 appengine 应用程序。

首先,我使用 gcloud cli 创建了所有基本资源。这里我列出我执行过的命令:

export PROJECT=ProjectName
export TF_VAR_billing_account=xxxxxx-xxxxxx-xxxxxx
export TF_VAR_project=${PROJECT}-terraform
export TF_CREDS=./${PROJECT}-terraform.json

gcloud projects create ${TF_VAR_project} \
  --set-as-default

gcloud beta billing projects link ${TF_VAR_project} \
  --billing-account ${TF_VAR_billing_account}

######################################################################################
##### Create the Terraform service account
######################################################################################

gcloud iam service-accounts create terraform \
  --display-name "Terraform admin account"

gcloud iam service-accounts keys create ${TF_CREDS} \
  --iam-account terraform@${TF_VAR_project}.iam.gserviceaccount.com

gcloud projects add-iam-policy-binding ${TF_VAR_project} \
  --member serviceAccount:terraform@${TF_VAR_project}.iam.gserviceaccount.com \
  --role roles/editor

gcloud projects add-iam-policy-binding ${TF_VAR_project} \
  --member serviceAccount:terraform@${TF_VAR_project}.iam.gserviceaccount.com \
  --role roles/storage.admin

gcloud …
Run Code Online (Sandbox Code Playgroud)

google-app-engine google-cloud-platform gcloud terraform

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

从 JPA 实体生成 CRUD

我有一个用 spring mvc 开发的 Web 应用程序,为了持久性,我使用 JPA(休眠实现),我想向该应用程序添加一个 CRUD GUI。

你知道一些允许我在我的项目中从 JPA 实体生成 CRUD GUI 的框架吗?

在此先感谢您的帮助

java user-interface spring crud

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

Spring Security,Rest api和Facebook从移动设备登录

我正在开发一个具有REST API的Web应用程序.目前,Api在服务器端受到弹簧安全保护,具有表单登录身份验证.最近我还添加了spring social以允许访问facebook和twitter,这一切都有效.因此,必须注册用户才能访问某个端点.

现在我必须构建一个必须访问REST API的移动应用程序,我想知道我应该使用什么策略.

我看到facebook有一个android/ios sdk允许在移动端进行身份验证.因此,一旦用户在移动设备上进行了身份验证,我应该向我的服务器发出请求,那么我应该如何验证服务器端的用户访问资源?

如果您认为这不是一个好的解决方案,您可以给我一个如何解决这个问题的建议吗?

java facebook spring-security spring-social

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

实体管理器不会在数据库中保留数据

通过实体管理器,我试图将实体保存在数据库中,但我无法保存它。这是我的配置。

我有这个实体:

@Entity
@Table(name = "User")
public class UserModel implements Serializable, ModelItem {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;

    @Column(nullable = false)
    private String username;

    @Column(nullable = false)
    private String password;

    @Column(nullable = false)
    private String name;

    private String surname;

    private String notes;

    private String cellphone;

    @Column(nullable = false)
    private String email;

    private Boolean enabled;

    //get and set methods
    .....
}
Run Code Online (Sandbox Code Playgroud)

和我的导入 bean 执行持久性操作:

@Repository
public class ImportServiceImpl implements ImportService {

    @PersistenceContext …
Run Code Online (Sandbox Code Playgroud)

spring jpa

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

Camel - Split()和doCatch(....)不起作用

我正在尝试构建一个尝试验证xml的路由,如果一切正确,则必须拆分此文件,否则抛出异常并且必须执行其他操作.所以我做了以下事情:

from("file:"+fileOutboxTransformed+"?preMove=inprogress&move="+backupFolderTransformed+"/"+labelMessageType+"_${date:now:yyyyMMddHHmmssSSS}-${file:name.noext}.${file:ext}")
    .log(LoggingLevel.INFO, "Got transformed file and sending it to jms queue: "+queue)
    .doTry()
        .to("validator:classpath:"+validator)
        .split(xPathMessageTypeSplit)
        .to("jms:"+queue+"?jmsMessageType=Text")
    .doCatch(ValidationException.class)
        .log(LoggingLevel.INFO, "Validation Exception for message ${body}")
        .to("xslt:classpath:"+transformationsErrorAfter)
        .split(xPathNotificationSplit)
        .to("file:"+fileOutboxInvalid+"?fileName=${file:name.noext}-${date:now:yyyyMMddHHmmssSSS}.err2")
    .end();
Run Code Online (Sandbox Code Playgroud)

但它不编译(如果我不使用拆分然后它编译和工作),错误是:

The method doCatch(Class<ValidationException>) is undefined for the type ExpressionNode
Run Code Online (Sandbox Code Playgroud)

所以我尝试了以下内容

from("file:"+fileOutboxTransformed+"?preMove=inprogress&move="+backupFolderTransformed+"/"+labelMessageType+"_${date:now:yyyyMMddHHmmssSSS}-${file:name.noext}.${file:ext}")
    .log(LoggingLevel.INFO, "Got transformed file and sending it to jms queue: "+queue)
    .doTry()
        .to("direct:validate")
    .doCatch(ValidationException.class)
        .log(LoggingLevel.INFO, "Validation Exception for message ${body}")
        .to("xslt:classpath:"+transformationsErrorAfter)
        .split(xPathNotificationSplit)
        .to("file:"+fileOutboxInvalid+"?fileName=${file:name.noext}-${date:now:yyyyMMddHHmmssSSS}.err2")
    .end();

    from("direct:validate")
        .to("validator:classpath:"+validator)
        .to("direct:split_message");

    from("direct:split_message")
        .split(xPathMessageTypeSplit)
        .to("jms:"+queue+"?jmsMessageType=Text");
Run Code Online (Sandbox Code Playgroud)

这次我得到重复端点的错误

 org.apache.camel.FailedToStartRouteException: Failed to start route route312 because of Multiple …
Run Code Online (Sandbox Code Playgroud)

apache-camel

3
推荐指数
1
解决办法
2730
查看次数

不在Spring引导,Thymeleaf和AngularJs应用程序中加载静态资源

我有一个Spring Boot项目,必须启动角度水疗.资源文件夹的结构如下:

在此输入图像描述

在templates/src文件夹中有我从控制器开始的index.html文件:

@RequestMapping("/")
String index() {
    return "src/index";
}
Run Code Online (Sandbox Code Playgroud)

通过这种方式,我成功启动了index.html,但所有的反应都在:

  • bower_components
  • SRC/JS
  • SRC/CSS

未正确加载.所以我添加了配置:

@Configuration
public class WebConfig extends WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter {

    private static final Logger LOGGER = Logger.getLogger(WebConfig.class);

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler(    "/js/**")
                .addResourceLocations(  "/templates/src/js/");
    }
}
Run Code Online (Sandbox Code Playgroud)

但是我仍然无法加载所有需要的资源,因为我得到了404

在此输入图像描述

我不明白我做错了什么.

这里也是index.html:

<!DOCTYPE html>
<html lang="en" data-ng-app="app">
<head>
  <meta charset="utf-8" />
  <title>Angular version | Angulr</title>
  <meta name="description" content="Angularjs, Html5, Music, Landing, 4 in 1 ui kits package" />
  <meta name="keywords" content="AngularJS, angular, bootstrap, admin, dashboard, panel, app, charts, …
Run Code Online (Sandbox Code Playgroud)

spring thymeleaf spring-boot

3
推荐指数
1
解决办法
8666
查看次数

Spring JPA Dao - 无法自动装配领域

我正在尝试设置Junit测试来测试JPA配置.该课程如下:

@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
public class OrderPersistenceTests {
    @Autowired
    public JpaDaoRole dr;

    @Transactional
    public void test1() throws Exception {
        Role r = new Role();
        r.setIdRole(18);
        r.setDescription("description");
        dr.persist(r);
        Role r1=dr.findById(r.getIdRole());
        assertEquals(r.getIdRole(), r1.getIdRole());
    }
}
Run Code Online (Sandbox Code Playgroud)

这里也是我的app-context配置:

<?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:context="http://www.springframework.org/schema/context"
    xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <description>Example configuration to get you started.</description>

    <!-- Generic -->
    <context:annotation-config />
    <tx:annotation-driven transaction-manager="transactionManager" />
 <context:component-scan base-package="com.windy.spring" />

    <!-- JPA -->

    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
    <tx:annotation-driven />
    <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/> 
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> …
Run Code Online (Sandbox Code Playgroud)

java junit spring dao

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

Spring 和 JPA:运行 JUnit 测试时出错

当我运行简单的 Junit 测试来测试 Jpa/Dao 配置时,出现以下错误:

2012-01-30 23:24:19,606 INFO [org.springframework.test.context.TestContextManager] - <@TestExecutionListeners is not present for class [class com.windy.spring.OrderPersistenceTests]: using defaults.>
2012-01-30 23:24:19,738 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - <Loading XML bean definitions from class path resource [com/windy/spring/OrderPersistenceTests-context.xml]>
2012-01-30 23:24:19,895 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - <Loading XML bean definitions from class path resource [META-INF/spring/app-context.xml]>
2012-01-30 23:24:20,111 INFO [org.springframework.context.support.GenericApplicationContext] - <Refreshing org.springframework.context.support.GenericApplicationContext@36b8bef7: startup date [Mon Jan 30 23:24:20 CET 2012]; root of context hierarchy>
2012-01-30 23:24:20,266 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] - <Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@291946c2: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,jpaDaoRole,jpaDaoUser,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor#0,org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0,entityManagerFactory,dataSource,transactionManager]; root …
Run Code Online (Sandbox Code Playgroud)

java spring jpa

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

没有找到能够从类型java.lang.String转换为类型@ org.springframework.data.repository.query.Param的转换器

我正在使用spring boot 1.1.5构建一个MongoDb rest应用程序.我创建了一个存储库:

@RepositoryRestResource(collectionResourceRel = "SourceProductV1Repository", path = "SourceProductV1Repository")
public interface SourceProductV1Repository extends MongoRepository<SourceProductV1Model, String> {

    public List<SourceProductV1Model> findByUser (@Param("user") MongoUser user);

}
Run Code Online (Sandbox Code Playgroud)

我定义了一个转换器将String转换为MongoUser(转换器在spring上下文中正确注册):

@Component
public class String2MongoUserConverter implements Converter<String, MongoUser>{
    private static final Log LOGGER =  LogFactory.getLog(String2MongoUserConverter.class.getName());

    @Override
    public MongoUser convert(String s) {
        return null;
    }
}
Run Code Online (Sandbox Code Playgroud)

所以当我尝试访问时 http://localhost:8080/SourceProductV1Repository/search/findByUser?user=test

我收到以下错误:

org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type java.lang.String to type @org.springframework.data.repository.query.Param com.ddelizia.model.MongoUser
    at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:291)
    at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:177)
    at org.springframework.data.rest.core.invoke.ReflectionRepositoryInvoker.prepareParameters(ReflectionRepositoryInvoker.java:265)
    at org.springframework.data.rest.core.invoke.ReflectionRepositoryInvoker.invokeQueryMethod(ReflectionRepositoryInvoker.java:230)
    at org.springframework.data.rest.webmvc.RepositorySearchController.executeQueryMethod(RepositorySearchController.java:236)
    at org.springframework.data.rest.webmvc.RepositorySearchController.executeSearch(RepositorySearchController.java:146)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native …
Run Code Online (Sandbox Code Playgroud)

spring-data spring-data-mongodb

0
推荐指数
1
解决办法
3万
查看次数