小编Raf*_*zcz的帖子

Spring Data不处理Pageable action参数创建

我有一个简单的控制器动作:

public class CategoriesController
{
    @RequestMapping(value = { "/", "" })
    public String list(
        Model model,
        @PageableDefault(size = CategoriesController.PAGE_LIMIT) Pageable pager
    )
    {
        // load page data
        Page<Category> page = this.categoryService.findAll(pager);

        /* action logic here */
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的pom.xml片段:

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>3.2.4.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>3.2.4.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>3.2.4.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-commons</artifactId>
        <version>1.6.4.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
        <version>1.5.0.RELEASE</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

添加到我之后applicationContext.xml:

<bean class="org.springframework.data.web.config.SpringDataWebConfiguration"/>
Run Code Online (Sandbox Code Playgroud)

我有以下错误:

org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.data.domain.Pageable]: Specified …
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc spring-data

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

cobertura-maven-plugin与FindBugs冲突

cobertura-maven-plugin2.6更新到2.7后, Cobertura插件与FindBugs插件冲突.FindBugs插件检测到cobertura检测代码中的错误:

[INFO] Incorrect lazy initialization of static field pl.chilldev.sites.commons.ErrorCode.__cobertura_counters in pl.chilldev.sites.commons.ErrorCode.__cobertura_init() [pl.chilldev.sites.commons.ErrorCode] In ErrorCode.java
Run Code Online (Sandbox Code Playgroud)

(当Cobertura插件verison设置为2.6时,一切正常)

以防万一,FindBugs插件版本是3.0.1.

是否可以设置这些插件以某种方式一起工作?

编辑1(pom.xml)

这是pom.xml主项目目录(子模块仅包含依赖项列表):

<?xml version="1.0" encoding="utf-8"?>
<!--
# This file is part of the pl.chilldev.sites.
#
# @copyright 2015 © by Rafa? Wrzeszcz - Wrzasq.pl.
-->
<project
    xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd
">
    <modelVersion>4.0.0</modelVersion>

    <!-- core project settings -->
    <groupId>pl.chilldev.sites</groupId>
    <artifactId>sites</artifactId>
    <packaging>pom</packaging>
    <version>0.0.1-SNAPSHOT</version>

    <!-- project meta info -->
    <name>ChillDev-Sites</name>
    <url><!-- TODO --></url>
    <description>Content sites storage service.</description>
    <inceptionYear>2015</inceptionYear> …
Run Code Online (Sandbox Code Playgroud)

findbugs cobertura maven

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

Spring和/或Hibernate:在表单提交后从一方保存多对多关系

上下文

我有两个实体之间的简单关联 - CategoryEmail(NtoM).我正在尝试创建用于浏览和管理它们的Web界面.我有一个简单的电子邮件订阅编辑表单,其中包含表示给定电子邮件所属类别的复选框列表(我注册了Set<Category>类型的属性编辑器).

问题

表格显示效果很好,包括标记当前指定的类别(对于现有的电子邮件).但是没有更改保存到EmailsCategories表(NtoM映射表,定义的表@JoinTable- 既没有添加新检查的类别,也没有删除未选中的类别.

代码

邮件实体:

@Entity
@Table(name = "Emails")
public class Email
{
    @Id
    @GeneratedValue(generator = "system-uuid")
    @GenericGenerator(name = "system-uuid", strategy = "uuid2")
    @Column(length = User.UUID_LENGTH)
    protected UUID id;

    @NaturalId
    @Column(nullable = false)
    @NotEmpty
    @org.hibernate.validator.constraints.Email
    protected String name;

    @Column(nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    protected Date createdAt;

    @Column
    protected String realName;

    @Column(nullable = false)
    protected boolean isActive = true;

    @ManyToMany(mappedBy = "emails", fetch = FetchType.EAGER)
    protected Set<Category> categories = new HashSet<Category>(); …
Run Code Online (Sandbox Code Playgroud)

many-to-many hibernate jpa spring-mvc hibernate-mapping

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

Spring MVC:在表单处理操作中有多个@ModelAttribute

上下文

我有两个实体之间的简单关联 - CategoryEmail(NtoM).我正在尝试创建用于浏览和管理它们的Web界面.要浏览类别并将电子邮件添加到该类别中,我使用@RequestMapping包含类别ID(UUID)的控制器,因此所有控制器操作始终在使用path指定的类别的上下文中进行.

我用来@ModelAttribute为整个控制器范围预加载上下文类别.

问题

这种方法适用于列表和显示表单.但是它在表单提交时失败 - 在稍微调试之后,我发现表单数据会覆盖我的类别@ModelAttribute参数.

在我的代码中,在方法中save(),category实际上并不是用addCategory()方法加载的模型属性,而是填充了表单数据(email模型也被填充,这是正确的).

我正在寻找能够将表单数据仅绑定到特定的解决方案@ModelAttribute.

我在Spring MVC文档中读到了参数的顺序很重要,但是我根据示例对它们进行了相应的排序,但它仍然没有像预期的那样工作.

代码

这是我的控制器:

@Controller
@RequestMapping("/emails/{categoryId}")
public class EmailsController
{
    @ModelAttribute("category")
    public Category addCategory(@PathVariable UUID categoryId)
    {
        return this.categoryService.getCategory(categoryId);
    }

    @InitBinder
    public void initBinder(WebDataBinder binder)
    {
        binder.registerCustomEditor(Set.class, "categories", new CategoriesSetEditor(this.categoryService));
    }

    @RequestMapping(value = "/create", method = RequestMethod.GET)
    public String createForm(@ModelAttribute Category category, Model model)
    {
        // here everything works, as …
Run Code Online (Sandbox Code Playgroud)

java spring annotations spring-mvc spring-annotations

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

maven-tomcat7-plugin生成损坏的可执行JAR

我使用Maven Tomcat7插件生成带有嵌入式Tomcat7实例的JAR存档时遇到问题.这是我的pom.xml片段:

        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <path>/${project.artifactId}</path>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>exec-war</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
Run Code Online (Sandbox Code Playgroud)

我的项目使用war包装.生成包含项目的WAR存档的Tomcat的JAR文件,但是当我尝试运行它时,我收到错误:

java.io.FileNotFoundException: /home/rafal.wrzeszcz/workspace/Mailer/.extract/webapps/mailer.war
    at java.util.zip.ZipFile.open(Native Method)
    at java.util.zip.ZipFile.<init>(ZipFile.java:214)
    at java.util.zip.ZipFile.<init>(ZipFile.java:144)
    at java.util.jar.JarFile.<init>(JarFile.java:153)
    at java.util.jar.JarFile.<init>(JarFile.java:90)
    at sun.net.www.protocol.jar.URLJarFile.<init>(URLJarFile.java:93)
    at sun.net.www.protocol.jar.URLJarFile.getJarFile(URLJarFile.java:69)
    at sun.net.www.protocol.jar.JarFileFactory.get(JarFileFactory.java:88)
    at sun.net.www.protocol.jar.JarURLConnection.connect(JarURLConnection.java:122)
    at sun.net.www.protocol.jar.JarURLConnection.getJarFile(JarURLConnection.java:89)
    at org.apache.catalina.startup.ExpandWar.expand(ExpandWar.java:113)
    at org.apache.catalina.startup.ContextConfig.fixDocBase(ContextConfig.java:722)
    at org.apache.catalina.startup.ContextConfig.init(ContextConfig.java:843)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:387)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:402)
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:110)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:722)
Run Code Online (Sandbox Code Playgroud)

我尝试了插件版本2.1 …

java jar war maven tomcat7

7
推荐指数
2
解决办法
2457
查看次数

在Docker中运行时,npm install导致cb()从不调用!

我有一个package.json文件很小的项目:

{
    "name": "chilldev-web",
    "version": "2.1.0-SNAPSHOT",
    "description": "Client-side build tool for a project.",
    "license": "UNLICENSED",
    "private": true,
    "dependencies": {
        "internal-edge-render": "file:/root/.m2/repository/pl/chilldev/internal/internal-edge-render/0.1.2/internal-edge-render-0.1.2.tar.gz",
        "react": "16.6.1",
        "react-dom": "16.6.1",
        "react-helmet": "5.2.0",
        "director": "1.2.8"
    },
    "devDependencies": {
        "typescript": "2.9.2",
        "browserify": "16.2.3",
        "gulp": "3.9.1",
        "tslint": "5.11.0",
        "tslint-react": "3.6.0",
        "cssnano": "4.1.7",
        "autoprefixer": "9.3.1",
        "envify": "4.1.0",
        "uglifyify": "5.0.1",
        "sassdoc": "2.5.1",
        "typedoc": "0.13.0",
        "gulp-typedoc": "2.2.0",
        "gulp-postcss": "8.0.0",
        "gulp-tslint": "8.1.3",
        "gulp-jscpd": "0.0.8",
        "gulp-sass": "4.0.2",
        "gulp-typescript": "4.0.2",
        "gulp-install": "1.1.0",
        "gulp-zip": "4.2.0",
        "gulp-concat": "2.6.1",
        "gulp-header": "2.0.5",
        "gulp-uglify": "3.0.1",
        "vinyl-source-buffer": "1.1.1", …
Run Code Online (Sandbox Code Playgroud)

node.js npm docker package.json

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

首次连接后,Netty服务器不接受连接

我在运行使用Netty的服务时遇到问题.它启动并正常工作,但只有一次.之后不接受任何连接(它们立即被丢弃).

我有多个监听器,每个监听器只接受ony连接,之后连接到同一个监听器是不可能的.

这是我的Listener.java:

public class Listener
{
    /* ... */

    public void run()
    {
        // check if there is any sense in running this listener
        if (this.address == null) {
            this.logger.info("\"{}\" was not enabled for connection, no point to start it.", this.getName());
            return;
        }

        final int maxPacketSize = this.getMaxPacketSize();
        final ChannelHandler handler = new DispatcherHandler<ContextType>(this.context, this.dispatcher);
        EventLoopGroup acceptors = new NioEventLoopGroup();
        EventLoopGroup workers = new NioEventLoopGroup();

        try {
            // network service configuration
            ServerBootstrap bootstrap = new ServerBootstrap(); …
Run Code Online (Sandbox Code Playgroud)

java nio netty

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

如何从加载中排除 bean?

我在将外部库与 Spring 集成时遇到问题。它包含一个用 注释的类@Configuration,它有一个用 注释的方法@Bean。我不希望它被实例化(它不需要并且引入了对Spring Boot 的依赖,我不使用它。

不幸的是,这个带@Configuration注释的类在库的其他地方使用(类类型需要,而不是接口类型,所以我需要准确地实例化这个类)。

我从自动扫描中排除了它的包,我没有直接导入它。只需手动构建它并在自己的配置中注册为 bean。

所以,简而言之 - 我需要注册一个 bean,但将它从注释扫描中排除(不处理它的注释@Bean方法)。有什么办法可以做到这一点?

java spring spring-mvc

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

Java9的Maven Site插件

我在使用Java9(Oracle JDK 9)在Travis上运行CI构建时遇到问题.

我失败了maven-site-plugin- 在移除之后一切都工作得很顺利.

我尝试删除其他所有内容以检查可能存在依赖性冲突,只剩下这一个插件构建仍然失败.它只是一个pom容器,仍然失败只有一个简单的站点插件(更新到声称已准备好java9的最新版本).

以下是所有资源:

在Web上寻找类似的问题我发现通常它的插件兼容性(所有插件更新)或不同的依赖版本,但我删除了所有这些并且它仍然失败.

构建在OpenJDK 9上本地运行完全正常.

-编辑-

从@nullpointer应用提示后:

java maven maven-site-plugin travis-ci java-9

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

如何重写 Spring Data JPA 存储库基本方法?

我有一些实体类型需要额外的保存逻辑(准确地说,我想在保存时保存位置)。我不想使用任何特定于数据库的功能(例如触发器)来执行此操作,因为我不确定将来使用的数据存储是什么。

所以我想重写save()方法。

在 Spring Data JPA 文档中,我可以看到两种为存储库类提供自己的实现的方法:

  1. 扩展基础存储库类并告诉 Spring Data 使用它。
  2. PositionedRepository使用实现类 ( )定义一个接口(在我的例子中我假设为) PositionedRepositoryImpl

第一种方法的问题 - 我不想为所有存储库实现它,只定位两种实体类型。

第二种方式的问题 - 我无法访问基本存储库方法,因此除了位置计算之外,我还需要以某种方式构建通常由基本存储库提供的所有查询。

有什么方法可以仅针对特定存储库类型扩展基本存储库类吗?

java spring hibernate spring-data-jpa

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