小编gre*_*fox的帖子

没有Spring Boot的Spring Boot Actuator

我一直在研究Spring/Spring MVC应用程序,我正在寻找性能指标.我遇到过Spring Boot Actuator,它看起来像是一个很好的解决方案.但是我的应用程序不是Spring Boot应用程序.我的应用程序运行在传统容器Tomcat 8中.

我添加了以下依赖项

// Spring Actuator
compile "org.springframework.boot:spring-boot-starter-actuator:1.2.3.RELEASE"
Run Code Online (Sandbox Code Playgroud)

我创建了以下配置类.

@EnableConfigurationProperties
@Configuration
@EnableAutoConfiguration
@Profile(value = {"dev", "test"})
@Import(EndpointAutoConfiguration.class)
public class SpringActuatorConfig {

}
Run Code Online (Sandbox Code Playgroud)

我甚至在每个配置类上添加@EnableConfigurationProperties,如StackOverflow上另一篇文章所建议的那样.然而,这没有做任何事情.端点仍未创建并返回404.

java spring spring-mvc spring-boot

52
推荐指数
5
解决办法
2万
查看次数

OS X 10.9 Mavericks上的PHP Xdebug

安装OS X 10.9 Mavericks后,我在OS X上设置PHP开发环境时遇到问题.

这是我用来安装的命令.

sudo pecl install xdebug

downloading xdebug-2.2.3.tgz ...
Starting to download xdebug-2.2.3.tgz (250,543 bytes)
.....................................................done: 250,543 bytes
66 source files, building
running: phpize
grep: /usr/include/php/main/php.h: No such file or directory
grep: /usr/include/php/Zend/zend_modules.h: No such file or directory
grep: /usr/include/php/Zend/zend_extensions.h: No such file or directory
Configuring for:
PHP Api Version:
Zend Module Api No:
Zend Extension Api No:
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.

ERROR: …
Run Code Online (Sandbox Code Playgroud)

php xdebug osx-mavericks

47
推荐指数
4
解决办法
6万
查看次数

Spring Security令牌认证 - RESTful JSON服务

我希望将Spring Security用于Spring MVC应用程序,该应用程序将严格地作为JSON Web服务.我做了一些研究并阅读了一些文章,但还没有找到任何完整的内容.我希望应用程序完全无状态并使用基于令牌的身份验证.我不希望Spring MVC应用程序有任何形式,或使用表单进行身份验证.它应该严格地接受JSON中的请求和数据,并返回JSON响应.

将会有一个Angular JS客户端应用程序,它需要发送用户名和密码,并从应用程序中获取令牌以用于顺序请求.在某些时候,也可能有Android客户端访问此Web服务.

我假设Spring Security在内部将令牌映射到用户会话,这意味着它知道令牌XXXXXXXXXXXX是管理员用户Bob而令牌AAAAAAAAAA是标准用户Joe.但是我对Spring Security没有多少经验,所以我不知道这一切是如何结合在一起的.我仍然希望能够在控制器和服务方法上使用安全注释.

有没有办法在Spring Security中实现这一目标?

这个问题似乎是一个很好的起点,但我不确定这是否可行,因为我设想通过Spring进行RESTful身份验证.

restful-authentication spring-mvc spring-security

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

Spring Data JPA中的动态查询

我正在寻找一个使用Spring Data JPA动态构建查询的解决方案.我有一个GameController,它有一个RESTful服务端点/游戏,有4个可选参数:流派,平台,年份,标题.API可以不传递,全部4,以及它们之间的每个组合.如果未传递任何参数,则默认为null.我需要一个存储库中的方法来构建适当的查询,理想情况下仍然允许Spring Data JPA Paging,尽管我不确定这是否可行.

我找到了这篇文章,但除非我误解,否则这似乎不是我需要的.http://spring.io/blog/2011/04/26/advanced-spring-data-jpa-specifications-and-querydsl/

我知道JPA有一个Query Criteria API,但实际上并不知道如何实现它.

我意识到我可以为每个可能的场景创建一个方法,但这似乎是非常糟糕的做法和许多不必要的代码.

GameRepository:

package net.jkratz.igdb.repository;

import net.jkratz.igdb.model.Game;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface GameRepository extends JpaRepository<Game, Long> {

    @Query("select g from Game g, GamePlatformMap gpm, Platform p where g = gpm.game and gpm.platform = p and p.id = :platform")
    Page<Game> getGamesByPlatform(@Param("platform") Long platformId, Pageable pageable);

    @Query("select g from Game g where g.title like :title")
    Page<Game> getGamesByTitle(@Param("title") String title, Pageable pageable);

    @Query("select g from Game …
Run Code Online (Sandbox Code Playgroud)

spring hibernate jpa spring-data spring-data-jpa

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

弹簧静止控制器返回特定字段

我一直在思考使用Spring MVC设计JSON API的最佳方法.我们都知道IO很昂贵,因此我不想让客户端进行多次API调用以获得他们需要的东西.但与此同时,我不一定要回厨房水槽.

作为一个例子,我正在开发类似于IMDB的游戏API,而不是用于视频游戏.

如果我返回与游戏相关的所有内容,它将看起来像这样.

/ API /游戏/ 1

{
    "id": 1,
    "title": "Call of Duty Advanced Warfare",
    "release_date": "2014-11-24",
    "publishers": [
        {
            "id": 1,
            "name": "Activision"
        }
    ],
    "developers": [
        {
            "id": 1,
            "name": "Sledge Hammer"
        }
    ],
    "platforms": [
        {
            "id": 1,
            "name": "Xbox One",
            "manufactorer": "Microsoft",
            "release_date": "2013-11-11"
        },
        {
            "id": 2,
            "name": "Playstation 4",
            "manufactorer": "Sony",
            "release_date": "2013-11-18"
        },
        {
            "id": 3,
            "name": "Xbox 360",
            "manufactorer": "Microsoft",
            "release_date": "2005-11-12"
        }
    ],
    "esrbRating": {
        "id": 1,
        "code": …
Run Code Online (Sandbox Code Playgroud)

java rest spring spring-mvc spring-restcontroller

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

Hibernate Native vs Hibernate JPA

Hibernate网站说有一个原生的Hibernate API以及一个JPA的实现.Native API和JPA实现之间有什么区别?优点缺点?

我正在使用Spring MVC应用程序,使用Tomcat作为容器,使用MySQL进行持久化.我过去分别使用Doctrine和Entity for PHP和.NET,使用代码优先方法.我想有类似Java的东西.我是Spring的新手,从未使用过Hibernate.我的团队想使用ORM,而Hibernate似乎是最受欢迎的.我们不确定Hibernate将如何锻炼,或者我们是否应该使用原生或JPA api.该应用程序将是数据驱动,数据输入,报告等.

我已经读过,使用JPA可以更容易地切换到另一个JPA实现,虽然我不知道是否需要它.

java persistence hibernate jpa

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

验证数据类参数Kotlin

如果我使用Kotlin数据类对我的值对象进行建模,那么处理验证的最佳方法是什么.似乎init块是唯一的逻辑位置,因为它在主构造函数之后执行.

data class EmailAddress(val address: String) {

    init {
        if (address.isEmpty() || !address.matches(Regex("^[a-zA-Z0-9]+@[a-zA-Z0-9]+(.[a-zA-Z]{2,})$"))) {
            throw IllegalArgumentException("${address} is not a valid email address")
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

使用JSR-303示例

其缺点是需要加载时间编织

@Configurable
data class EmailAddress(@Email val address: String) {

    @Autowired
    lateinit var validator: Validator

    init {
        validator.validate(this)
    }
}
Run Code Online (Sandbox Code Playgroud)

kotlin

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

使用Python正则表达式提取数据

我在使用Python正则表达式时遇到麻烦,想出一个正则表达式来提取特定值.

我试图解析的页面有许多productIds,它们以下列格式显示

\"productId\":\"111111\"
Run Code Online (Sandbox Code Playgroud)

111111在这种情况下,我需要提取所有值.

python regex parsing

12
推荐指数
2
解决办法
6万
查看次数

Spring Security禁用登录页面/重定向

有没有办法禁用Spring Security和登录页面的重定向.我的要求指定登录应该是导航菜单的一部分.

例:

在此输入图像描述

因此,没有专用的登录页面.登录信息需要通过Ajax提交.如果发生错误,则应返回指定错误的JSON并使用正确的HTTP状态代码.如果身份验证检出它应该返回200然后javascript可以从那里处理它.

我希望这是有道理的,除非有更简单的方法来实现Spring Security.我对Spring Security没有多少经验.我认为这必须是一种常见的做法,但我没有找到太多.

当前的弹簧安全配置

@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Autowired
    private UserDetailsService userDetailsService;

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .antMatchers("/", "/public/**").permitAll()
                .antMatchers("/about").permitAll()
                .anyRequest().fullyAuthenticated()
                .and()
                .formLogin()
                .loginPage("/login")
                .failureUrl("/login?error")
                .usernameParameter("email")
                .permitAll()
                .and()
                .logout()
                .logoutUrl("/logout")
                .deleteCookies("remember-me")
                .logoutSuccessUrl("/")
                .permitAll()
                .and()
                .rememberMe();
    }

    @Override
    public void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth
                .userDetailsService(userDetailsService)
                .passwordEncoder(new BCryptPasswordEncoder());
    }
Run Code Online (Sandbox Code Playgroud)

更新:

我尝试使用HttpBasic()然后它要求登录信用无关紧要什么及其丑陋的浏览器弹出窗口是最终用户不能接受的.看起来我可能需要扩展AuthenticationEntryPoint.

在一天结束时,我需要Spring安全性发回JSON,说验证成功或失败.

spring spring-security

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

使用Twirl和Spring MVC

是否可以将Twirl与Spring MVC一起用作视图技术?我想用一些代替JSP的东西,Apache Tiles对我来说很麻烦.旋转视图技术为Play Framework看起来非常酷,类似于ASP.NET Razor.

https://www.playframework.com/documentation/2.3.x/JavaTemplates

我做了一个快速的谷歌搜索,但没有发现太多.

java spring spring-mvc playframework twirl

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