小编lrk*_*kwz的帖子

Spring数据查询,其中列为null

假设我有实体(为了简洁省略了getter/setter和各种细节):

@Entity
class Customer{
    ...
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "customer")
    Collection<Coupon> coupons;
}

@Entity
class Coupon{
    ...
    @Temporal(value = TemporalType.TIMESTAMP)
    private Date usedOn;

    @ManyToOne(fetch = FetchType.LAZY)
    @NotNull
    Customer customer;
}
Run Code Online (Sandbox Code Playgroud)

我希望检索具有null usedOn的给定客户的所有优惠券.我没有成功定义CouponRepository中的方法,如文档中所述

@Repository
public interface CouponRepository extends CrudRepository<Coupon, Long> {
     Collection<Coupon> findByCustomerAndUsedOnIsNull(Customer);
}
Run Code Online (Sandbox Code Playgroud)

但这会导致编译错误Syntax error, insert "... VariableDeclaratorId" to complete FormalParameterList.

spring spring-data spring-data-jpa

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

是否需要web.xml来部署Spring引导应用程序

我试图将弹簧启动应用程序打包为战争.根据这个,我修改了应用程序类:

@SpringBootApplication
@EntityScan({"org.mdacc.rists.cghub.model"}) 
@EnableJpaRepositories(basePackages = {"org.mdacc.rists.cghub.ws.repository"})
public class Application extends SpringBootServletInitializer
{

    public static void main( String[] args )
    {
        SpringApplication.run(Application.class, args);
    }

    @Override
     protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
         return application.sources(Application.class);
     }
}
Run Code Online (Sandbox Code Playgroud)

还在我的pom.xml中添加了以下内容

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>provided</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)

当我打包项目时,我收到以下错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war (default-war) on project cg-web: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1]
Run Code Online (Sandbox Code Playgroud)

当我阅读spring boot应用程序时,我从未见过有关创建web.xml的任何内容.将Spring启动应用程序部署为战争需要web.xml吗?

java web-services war spring-boot

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

@Secured与@Roles之间的区别是否在Spring?以及基于角色的安全性的概念?

我正在研究Spring Security,我对使用@Secured注释和@RolesAllowed注释之间的区别有以下疑问.

我知道两者都必须在方法层面使用,在我的学习材料上我发现了以下两个例子:

  • @RolesAllowed注释:

    import javax.annotation.security.RolesAllowed;    
    public class ItemManager {
        @RolesAllowed("ROLE_MEMBER")
        public Item findItem(long itemNumber) {
            ...
        }
    }
    
    Run Code Online (Sandbox Code Playgroud)
  • @Secured注释:

    import org.springframework.security.annotation.Secured;
    public class ItemManager {
        @Secured("ROLE_MEMBER")
        public Item findItem(long itemNumber) {
            ...
        }
    }
    
    Run Code Online (Sandbox Code Playgroud)

在我看来,这两个注释以相同的方式工作.有什么区别?我错过了什么?

我的另一个疑问是:究竟代表ROLE_MEMBER的是什么?

我认为这类似于基于角色的安全性,所以它可能意味着:只有当用户是成员时才可以访问带注释的资源(它是否正确?).但在何处以及如何定义用户已设置此角色(它是成员)的事实?究竟如何运作?

TNX

java spring annotations spring-mvc spring-security

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

什么可能导致原始'OAuth2'状态参数在org.springframework.social.connect.web.ConnectSupport中为null?

我正在尝试在我的应用程序上使用Spring Social,并且在调试时注意到我的应用程序上原始的"OAuth2"状态参数始终为null.

请参阅org.springframework.social.connect.web.ConnectSupport下面的Spring Social源代码:

private void verifyStateParameter(NativeWebRequest request) {
    String state = request.getParameter("state");
    String originalState = extractCachedOAuth2State(request);//Always null...
    if (state == null || !state.equals(originalState)) {
        throw new IllegalStateException("The OAuth2 'state' parameter is missing or doesn't match.");
    }
}

private String extractCachedOAuth2State(WebRequest request) {
    String state = (String) sessionStrategy.getAttribute(request, OAUTH2_STATE_ATTRIBUTE);
    sessionStrategy.removeAttribute(request, OAUTH2_STATE_ATTRIBUTE);
    return state;       
}
Run Code Online (Sandbox Code Playgroud)

有人可以帮忙吗?

编辑:我确实看到facebook传回的状态参数:

Request URL:https://www.facebook.com/v2.5/dialog/oauth?client_id=414113641982912&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Fconnect%2Ffacebook&scope=public_profile&state=0b7a97b5-b8d1-4f97-9b60-e3242c9c7eb9
Request Method:GET
Status Code:302 
Remote Address:179.60.192.36:443
Run Code Online (Sandbox Code Playgroud)

编辑2:顺便说一下,我得到的例外情况如下:

Exception while handling OAuth2 callback (The OAuth2 'state' parameter is missing …
Run Code Online (Sandbox Code Playgroud)

oauth-2.0 spring-social spring-social-facebook

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

鱼壳中的字符串操作

我希望编写一个fish shell脚本来自动将JAVA_HOME初始化为当前配置的java-alternative.

在bash中它看起来像这样(对于丑陋的双重dirname感到抱歉)

j=`update-alternatives --query javac | grep Value:`
JAVA_HOME=`dirname ${j#Value:}`
JAVA_HOME=`dirname $JAVA_HOME`
export JAVA_HOME
Run Code Online (Sandbox Code Playgroud)

鱼怎么样?

set j (update-alternatives --query javac | grep Value:)
set JAVA_HOME (dirname ${j#Value:}) <-- this won't work!!
set JAVA_HOME (dirname $JAVA_HOME)
set --export JAVA_HOME
Run Code Online (Sandbox Code Playgroud)

fish

8
推荐指数
2
解决办法
8787
查看次数

任务抛出错误= 7:参数列表太长

我有一个Ant的build.xml文件,它在我的机器(Ubuntu)上没有问题执行,但抛出以下错误:

/var/lib/hudson/workspace/myproject/build.xml:254: Error running /var/lib/hudson/tools/java_6/bin/javac compiler
at org.apache.tools.ant.taskdefs.compilers.DefaultCompilerAdapter.executeExternalCompile(DefaultCompilerAdapter.java:525)
(...)
Caused by: java.io.IOException: Cannot run program "/var/lib/hudson/tools/java_6/bin/javac": java.io.IOException: error=7, Argument list too long
at java.lang.ProcessBuilder.start(ProcessBuilder.java:460)
at java.lang.Runtime.exec(Runtime.java:593)
at org.apache.tools.ant.taskdefs.Execute$Java13CommandLauncher.exec(Execute.java:862)
at org.apache.tools.ant.taskdefs.Execute.launch(Execute.java:481)
at org.apache.tools.ant.taskdefs.Execute.execute(Execute.java:495)
at org.apache.tools.ant.taskdefs.compilers.DefaultCompilerAdapter.executeExternalCompile(DefaultCompilerAdapter.java:522)
... 19 more
Caused by: java.io.IOException: java.io.IOException: error=7, Argument list too long
at java.lang.UNIXProcess.<init>(UNIXProcess.java:148)
at java.lang.ProcessImpl.start(ProcessImpl.java:65)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:453)
... 24 more
Run Code Online (Sandbox Code Playgroud)

参数列表相当大,实际上包含了WEB-INF/lib231650个字符长的所有jar文件!任何建议如何解决?

ant shell

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

如何在 symfony 上定义后代顺序索引

我想在 Doctrine 中创建以下 PostgreSQL 索引。

CREATE INDEX xxxx ON my_table (start_date, end_date DESC);
Run Code Online (Sandbox Code Playgroud)

我在实体注释中写了注释,但发生了 SchemaException 错误。

/**
 * @ORM\Table(
 *     Indexes={
 *         @ORM\Index(columns={"start_date", "end_date DESC"})
 *     }
 * }
 */
 class MyTable
 {
     // snip
 }
Run Code Online (Sandbox Code Playgroud)

我应该如何编写“DESC”关键字注释?

php symfony

5
推荐指数
0
解决办法
581
查看次数

如何在 hibernate hbm.xml 中定义 char(2) 列?

您好,必须修改一些 Hibernate 遗留代码,我应该定义一个 SQL char(2) 列(char(2) 主键的外键)。

我的定义文件包含:

    <property
        name="language"
        type="char"
        update="true"
        insert="true"
        column="LANGUAGE"
        length="2"
    />
Run Code Online (Sandbox Code Playgroud)

但休眠生成:

+---------------------+--------------+------+-----+---------+----------------+
| Field               | Type         | Null | Key | Default | Extra          |
+---------------------+--------------+------+-----+---------+----------------+
(...)
| LANGUAGE            | char(1)      | YES  |     | NULL    |                |    
+---------------------+--------------+------+-----+---------+----------------+
Run Code Online (Sandbox Code Playgroud)

外键表类似于:

+--------------+--------------+------+-----+---------+-------+
| Field        | Type         | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+-------+
| LANGUAGE     | char(2)      | NO   | PRI | NULL    |       |
(...)
+--------------+--------------+------+-----+---------+-------+
Run Code Online (Sandbox Code Playgroud)

使用:

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>3.3.1.GA</version> …
Run Code Online (Sandbox Code Playgroud)

java hibernate

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

在风帆和水线中使用AND和OR子句的混合

如何在Sailsjs及其ORM水线中使用OR和AND子句?例如,我有一张书桌

 _______________________________________
| book_name | author   | free  | public |  
 _______________________________________
| Book-A    | Author-1 | false | true   |
 ---------------------------------------
| Book-B    | Author-1 | true  | true   |
 ---------------------------------------
| Book-C    | Author-1 | false | false  |
 ---------------------------------------
| Book-D    | Author-2 | true  | true   |
 ---------------------------------------
Run Code Online (Sandbox Code Playgroud)

我想获得作者-1的书籍,这些书籍是公开的或免费的,即Book-A和Book-B.如何使用Sails.js编写此查询

sails.js waterline

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

无法执行目标 org.springframework.boot:spring-boot-maven-plugin:1.5.6.RELEASE

我是 spring boot 的新手,尝试解决这个问题一周。我下载plugin并仍然收到相同的错误,如果需要,我没有代理的工具/选项

编辑 我刚刚创建了一个用户可以注册或登录的基本项目。我有控制器、服务存储库、域类。但是当我想检查我的数据库是否创建时,我收到了这个错误。我检查了我plugins是否错过了一些但是一切似乎都正确。你能给我一些猜测可能是什么问题吗?

我的 pom.xml

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.6.RELEASE</version>
    <relativePath/>
    <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    
    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>javax.persistence</artifactId>
        <version>2.1.0</version>
        <type>jar</type>
    </dependency>
    
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-commons</artifactId>
        <version>1.13.6.RELEASE</version>
        <type>jar</type>
    </dependency>
    
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
        <version>1.11.6.RELEASE</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <version>1.5.6.RELEASE</version>
        <type>jar</type>
    </dependency>
</dependencies>

<build>
    <plugins>
        
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>1.5.6.RELEASE</version>
            <configuration>
                <fork>true</fork>
            </configuration>
        </plugin>
        
    </plugins> …
Run Code Online (Sandbox Code Playgroud)

java spring maven

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