小编geo*_*and的帖子

Spring安全和Thymeleaf不起作用

我正在使用Spring 4和Thymeleaf在我的index.xhtml页面中我写道:

  <!DOCTYPE html>
  <html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:th="http://www.thymeleaf.org"
        xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
        xmlns:sec="http://www.thymeleaf.org/extras/spring-security"
        layout:decorator="layouts/layout">

  <head>
      <title>Welcome</title>
  </head>
  <body>
....
  <div sec:authorize="hasRole('ROLE_ADMIN')">
      You are authorized user! Hi, <span sec:authentication="name">Username</span>
  </div>
  <div sec:authorize="isAnonymous()">
       You are NOT authorized user!
  </div>
...
</body></html>
Run Code Online (Sandbox Code Playgroud)

结果我看到:

您是授权用户!嗨,用户名您不是授权用户!

即Spring Security不起作用

我的build.gradle(一些dependecies)是:

compile 'org.thymeleaf:thymeleaf-spring4:2.1.2.RELEASE'
compile 'org.thymeleaf.extras:thymeleaf-extras-springsecurity3:2.1.1.RELEASE'
compile 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:1.2.3'
compile 'org.springframework.security:spring-security-core:3.2.0.RELEASE'
compile 'org.springframework.security:spring-security-web:3.2.0.RELEASE'
compile 'org.springframework.security:spring-security-config:3.2.0.RELEASE'
compile 'org.springframework.security:spring-security-taglibs:3.2.0.RELEASE'
Run Code Online (Sandbox Code Playgroud)

我的spring-security.xml是:

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
             xmlns:beans="http://www.springframework.org/schema/beans"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:context="http://www.springframework.org/schema/context"
             xsi:schemaLocation="http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <!-- ????????? ????????? ???????????? -->
    <authentication-manager>
        <authentication-provider>
            <password-encoder ref="bCryptPasswordEncoder">
            </password-encoder>
            <jdbc-user-service …
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc spring-security thymeleaf

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

Netbeans 8 不会重新加载静态 Thymeleaf 文件

我正在通过 Maven 使用 Spring Boot 和 Thymeleaf。当我进行更改时,我似乎无法让 Netbeans 自动重新部署我的任何 Thymeleaf 模板文件。为了查看更改,我需要进行完整的清理/构建/运行。这需要太长时间。

模板在src/main/resources/templates. 我在 src/main/resources/ 中有一个 application.properties 文件,带有spring.thymeleaf.cache=falsespring.template.cache=false

我在项目设置中打开了“保存时编译”、“保存时复制资源”和“保存时部署”。

我的 Maven 构建生成了一个战争文件,Netbeans 将其部署到 Tomcat,我正在使用注释@EnableAutoConfiguration

Netbeans热部署对 Java 类的更改,但不会对 src/main/resources/ 中的任何静态文件进行热部署。

使用中的软件:

  • Mac OS X 10.9.4
  • 爪哇 1.8
  • Netbeans 8.0.1
  • 雄猫 8.0.12
  • 弹簧靴 1.1.7
  • Thymeleaf 2.1.3(通过 Spring Boot)

非常感谢任何指导。

spring netbeans maven thymeleaf spring-boot

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

使用ByteBuddy定义具有通用类型的字段

我刚开始与ByteBuddy一起玩,并且正在研究几个示例,以便掌握它。

我试图通过此练习完成的工作是用ByteBuddy替换一些使用ASM的代码。

到目前为止,当涉及到非泛型类型时,我已经取得了成功。例如,我可以轻松地定义一个像这样的字段

builder.defineField("names", List.class, Visibility.PRIVATE)
Run Code Online (Sandbox Code Playgroud)

如果我只想创建一个原始List类型的字段。

但是,在介绍泛型时,我很困惑。

显然,我定义字段的方式(使用Class)意味着通用类型会丢失。阅读文档(尤其是该Working with generic types部分)后,我无法真正弄清楚如果List字段具有已知的通用类型(例如,如果它是另一个POJO)如何构造List字段。假设我有以下POJO:

public class Dummy {
   private String name;

   //getters, setters
}
Run Code Online (Sandbox Code Playgroud)

并且我想创建一个的字段List<Dummy>,我将如何完成这样的任务?

谢谢!

java byte-buddy

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

如何在 Quarkus 中设置日志记录级别?

我想更改 Quarkus 应用程序的日志记录级别。

如何从配置文件或在运行时执行此操作?

quarkus

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

测试我的Quarkus应用程序时如何使用内存中的H2数据库?

我计划将PostgreSQL用作Quarkus应用程序的数据库,但我希望在测试中使用H2的便利。

有什么办法可以实现这样的壮举吗?

quarkus

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

对hibernate应用程序使用@Transactional注释会导致错误

我想在今天早上将春天与冬眠融为一体.我想使用spring transaction manager.但得到以下错误.该错误与@Trasactional Annotation有关.如果我删除注释,我能够从弹簧容器中获取bean.

Exception in thread "main" java.lang.ClassCastException: com.sun.proxy.$Proxy19 cannot be cast to com.hibernate.dao.EvntDAOImpl
at com.hibernate.action.HibernateAction.main(HibernateAction.java:17)
Run Code Online (Sandbox Code Playgroud)

我粘贴在我的源代码下面.

的pom.xml

<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>hibernate-tutorials</groupId>
<artifactId>hibernate-tutorials</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
    </plugins>
</build>
<properties>
    <spring-framework.version>4.0.3.RELEASE</spring-framework.version>
    <hibernate.version>4.3.5.Final</hibernate.version>
     <slf4j.version>1.7.5</slf4j.version>
</properties>
<dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${spring-framework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>${spring-framework.version}</version>
    </dependency>

    <!-- Spring ORM support -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${spring-framework.version}</version>
    </dependency>

    <!-- Logging with SLF4J & LogBack -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>${slf4j.version}</version>
        <scope>compile</scope>
    </dependency> …
Run Code Online (Sandbox Code Playgroud)

java spring hibernate spring-transactions

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

如何记录由 Quarkus 应用程序创建的 SQL 语句?

我正在使用带有 Hibernate 扩展的 Quarkus 应用程序,我希望 Hibernate 显示生成的 SQL 查询。我不确定如何实现。

实现这一目标的最佳方法是什么?配置此类功能的正确方法是什么?

quarkus

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

如何调试在开发模式下运行的Quarkus应用程序?

我已经使用Quarkus dev模式(mvn quarkus:dev)启动了应用程序,并且希望能够对其进行调试。

那怎么办

quarkus

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

如何向 Quarkus 应用程序添加 http 拦截器?

我想在我的 Quarkus 应用程序中添加一个 HTTP 拦截器,以便我可以拦截所有 HTTP 请求。怎样才能做到这一点?

quarkus

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

无法将Spring数据的依赖项添加到Spring引导中

我试图从Spring引导指南开始,并手动包含Spring-data的依赖项.

我的IDE是eclipse,我选择使用Gradle来构建项目.

双方build.gradlepom.xml已被修改,但仍然日食发现不能春季数据的库(例如org.springframework.data.*在编译过程中).

以下是我build.gradlepom.xml.

有人可以建议我哪里出错吗?谢谢!!

的build.gradle

buildscript {
    repositories {
            maven { url "http://repo.spring.io/libs-release" }
            mavenLocal()
            mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.1.1.RELEASE")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'war'

war {
    baseName = 'Xiwami'
    version =  '0.1.0'
}

jar {
    baseName = 'Xiwami'
    version =  '0.1.0'
}

repositories {
    mavenLocal()
    mavenCentral()
    maven { url "http://repo.spring.io/libs-release" }
maven { url …
Run Code Online (Sandbox Code Playgroud)

java spring gradle spring-data spring-boot

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