- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试自定义 UserDetailsService
,我的类是:
@Service
public class UserService implements UserDetailsService {
@Override
// @Transactional
public UserPrincipal loadUserByUsername(String username) {
UserPrincipal principal = userRepository.getByUsername(username);
// make sure the authorities and password are loaded
principal.getAuthorities().size();
principal.getPassword();
return principal;
}
}
我的 UserPrincipal
是:
@Entity
@Table
public class UserPrincipal implements UserDetails, CredentialsContainer, Cloneable {
...
private Set<UserAuthority> authorities = new HashSet<>();
@Override
@ElementCollection(fetch = FetchType.LAZY)
@CollectionTable(name = "UserPrincipal_Authority", joinColumns = {
@JoinColumn(name = "UserId", referencedColumnName = "UserId")
})
public Set<UserAuthority> getAuthorities()
{
return this.authorities;
}
...
}
配置:
<?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:jee="http://www.springframework.org/schema/jee"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.1.xsd">
<import resource="securityConfig.xml" />
<context:annotation-config />
<context:component-scan base-package="com">
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
</context:component-scan>
<!-- Configure the data source bean -->
<jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/test"/>
<!-- Create default configuration for Hibernate -->
<bean id="hibernateJpaVendorAdapter"
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
<!-- Configure the entity manager factory bean -->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter"/>
<!-- Set JPA properties -->
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
<prop key="javax.persistence.schema-generation.database.action">none</prop>
<!--<prop key="hibernate.ejb.use_class_enhancer">true</prop>-->
</props>
</property>
<!-- Set base package of your entities -->
<property name="packagesToScan" value="com.security"/>
<!-- Set share cache mode -->
<property name="sharedCacheMode" value="ENABLE_SELECTIVE"/>
<!-- Set validation mode -->
<property name="validationMode" value="NONE"/>
</bean>
<!-- Configure the transaction manager bean -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<!-- Enable annotation driven transaction management -->
<tx:annotation-driven/>
<!--
Configure Spring Data JPA and set the base package of the
repository interfaces
-->
<jpa:repositories base-package="com.security"
entity-manager-factory-ref="entityManagerFactory"
transaction-manager-ref="transactionManager"/>
</beans>
当 @Transactional
被注释掉时,我明白了
Reason: failed to lazily initialize a collection of role:
com.security.UserPrincipal.authorities
, could not initialize proxy - no Session"
这是有道理的。当我添加 @Transactional
时,出现此错误:
No qualifying bean of type [
com.security.UserService
] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency.
代码曾经有效,我无法弄清楚我更改了什么破坏了代码。
这是完整的异常:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'securityController' defined in file [C:\Users\nfallah\Documents\workspace-intelliJ\Spring-Hybrid-Config - MVC - CSR - Secure - DB\target\spring-hybrid-config-1.0.0-SNAPSHOT\WEB-INF\classes\com\security\SecurityController.class]: Unsatisfied dependency expressed through constructor argument with index 1 of type [com.security.UserService]: : No qualifying bean of type [com.security.UserService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.security.UserService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:742) ~[ConstructorResolver.class:4.0.1.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:196) ~[ConstructorResolver.class:4.0.1.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1114) ~[AbstractAutowireCapableBeanFactory.class:4.0.1.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1017) ~[AbstractAutowireCapableBeanFactory.class:4.0.1.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504) ~[AbstractAutowireCapableBeanFactory.class:4.0.1.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) ~[AbstractAutowireCapableBeanFactory.class:4.0.1.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) ~[AbstractBeanFactory$1.class:4.0.1.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[DefaultSingletonBeanRegistry.class:4.0.1.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) ~[AbstractBeanFactory.class:4.0.1.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) ~[AbstractBeanFactory.class:4.0.1.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:700) ~[DefaultListableBeanFactory.class:4.0.1.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760) ~[AbstractApplicationContext.class:4.0.1.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482) ~[AbstractApplicationContext.class:4.0.1.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:658) ~[FrameworkServlet.class:4.0.1.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:624) ~[FrameworkServlet.class:4.0.1.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:672) ~[FrameworkServlet.class:4.0.1.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:543) ~[FrameworkServlet.class:4.0.1.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:484) [FrameworkServlet.class:4.0.1.RELEASE]
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136) [HttpServletBean.class:4.0.1.RELEASE]
at javax.servlet.GenericServlet.init(GenericServlet.java:158) [servlet-api.jar:3.1.FR]
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1241) [catalina.jar:8.0.8]
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1154) [catalina.jar:8.0.8]
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1041) [catalina.jar:8.0.8]
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4922) [catalina.jar:8.0.8]
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5204) [catalina.jar:8.0.8]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [catalina.jar:8.0.8]
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:724) [catalina.jar:8.0.8]
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700) [catalina.jar:8.0.8]
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:697) [catalina.jar:8.0.8]
at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1588) [catalina.jar:8.0.8]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_05]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_05]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_05]
at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0_05]
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300) [tomcat-coyote.jar:8.0.8]
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) [?:1.8.0_05]
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) [?:1.8.0_05]
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:463) [catalina.jar:8.0.8]
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:413) [catalina.jar:8.0.8]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_05]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_05]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_05]
at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0_05]
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300) [tomcat-coyote.jar:8.0.8]
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) [?:1.8.0_05]
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) [?:1.8.0_05]
at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1466) [?:1.8.0_05]
at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76) [?:1.8.0_05]
at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1307) [?:1.8.0_05]
at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1399) [?:1.8.0_05]
at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:828) [?:1.8.0_05]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_05]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_05]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_05]
at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0_05]
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:323) [?:1.8.0_05]
at sun.rmi.transport.Transport$1.run(Transport.java:178) [?:1.8.0_05]
at sun.rmi.transport.Transport$1.run(Transport.java:175) [?:1.8.0_05]
at java.security.AccessController.doPrivileged(Native Method) [?:1.8.0_05]
at sun.rmi.transport.Transport.serviceCall(Transport.java:174) [?:1.8.0_05]
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:557) [?:1.8.0_05]
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:812) [?:1.8.0_05]
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:671) [?:1.8.0_05]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_05]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_05]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_05]
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.security.UserService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1100) ~[DefaultListableBeanFactory.class:4.0.1.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:960) ~[DefaultListableBeanFactory.class:4.0.1.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:855) ~[DefaultListableBeanFactory.class:4.0.1.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:806) ~[ConstructorResolver.class:4.0.1.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:734) ~[ConstructorResolver.class:4.0.1.RELEASE]
... 65 more
最佳答案
当您添加 @Transactional
时,Spring 会生成 UserService
的代理,除非您另有说明,否则 Spring 默认使用基于接口(interface)的代理(使用动态代理API)。
因此,您应该依赖的类型是 UserDetailsService
,因为它是接口(interface)类型,因此也是创建的 bean 的类型。
它更喜欢使用接口(interface)的原因是它比使用 CGLIB 方法(当您设置 proxy-target-class=true
时使用它)更轻量级。
关于java - 未能延迟初始化角色自定义 UserDetailsService 的集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25100535/
抱歉,问题标题含糊不清!我有一个 ASP.NET 应用程序,可与其他第三方软件配合使用(Burning Glass - 通过 tcp/ip 连接到 Web 应用程序,需要 - 正确配置的 dns 条目
我正在开展一个项目,将一个大型网站分解为更小、更具体的网站。我需要能够将对这些网站的访问限制为仅具有必要权限的用户,并且希望尽可能利用现有的成员资格/角色数据模型。 因此,理想情况下,我想将潜在的多个
抱歉,问题标题含糊不清!我有一个 ASP.NET 应用程序,可与其他第三方软件配合使用(Burning Glass - 通过 tcp/ip 连接到 Web 应用程序,需要 - 正确配置的 dns 条目
我对 FOSUserBundle 中的角色有点困惑。用户实体也有角色列,我们可以通过它为用户分配多个角色。根据发布在 Managing users/roles/groups in FOSUserBun
原谅我的新手问题,但我想按顺序执行三个任务并在剧本中使用两个角色: 任务 角色 任务 角色 任务 这是我到目前为止(任务,角色,任务): --- - name: Task Role Task ho
在触发器中,我想检查哪些角色对 USER() 有效,而不是 CURRENT_USER()。(认识到 CURRENT_USER() 返回触发器的 DEFINER)。 是否有任何类型的 USER_ROLE
我有一套Ansible playbooks 和主要的 yml 文件是这样的 - hosts: all roles: - common - install_nginx 我想在触发剧本
因此,我有以下代码输出安装的所有功能和角色: Import-Module ServerManager $Arr = Get-WindowsFeature | Where-Object {$_.Inst
我已经寻找了一段时间,并且已经手动完成了角色和权限的许多部署,但是有什么方法可以在Sitecore中为角色/权限创建一个程序包(或等效程序包)? 当您没有选择从一个环境到另一个环境进行完全部署时,使用
我想找到或创建一个与所有者或至少贡献者具有相同功能的 azure 角色。但此角色不应该有权创建 azure 资源。 我一直在浏览现有的预定义角色。 最佳答案 这在 Azure RBAC 上下文中没有任
我在文档中找不到答案,也找不到示例:是否可以在 role/defaults/ 中命名除 main.yml 之外的文件?我的意思是,main.yml 是具有默认值的文件的唯一有效名称吗? 最佳答案 根据
我尝试了kubectl get sa default命令,但只看到一些非常基本的值。在k8s中查看与特定服务帐户关联的权限/角色的命令是什么? 最佳答案 以下命令可能会有所帮助。它基本上获得RoleB
有没有办法告诉 Spring 在我制作的自定义用户 bean 中找到用户的角色? http://static.springsource.org/sprin...ns-config.html 因此,如果
在我的 playbook 中运行几次 Play 后,我想验证我的应用程序的部署。 在我的角色之一中,我有以下任务,将创建的 ec2 实例添加到“已启动”的主机: - name: Add new ins
我按如下方式将用户添加到角色(请注意,我在我的机器上运行下面显示的代码): Roles.AddUserToRole(oMU.UserName, "Role1"); 使用以下代码我检查用户是否在
我目前在为 postgresql 创建角色时遇到问题,这是我已经做过的,但自昨晚以来取得了任何进展 simplybel@simplybel:~$ sudo -u postgres createuser
一个项目现在有超过 200 个类,每个文件一个类,将它们划分到目录中似乎是恰当的。现在我正在考虑两种不同的策略; a) 按角色或层分组 repositories/ UserRepository
您如何为用户、角色和应用特定实体提供种子?似乎 IdentityModel 以它自己的上下文为目标? internal sealed class Configuration : DbMigration
摩尔庄园手游在六一儿童节上线之后,网上的争议声还是很多的,有夸赞的,称其找回了童年的回忆,也有吐槽的,觉得3d的设计很晕,没有以前的感觉,想要删除账号,那么大家知道怎么去注销吗,步骤流程是什么样的?
在 XP SP2 虚拟机中运行 Oracle 11gR1。完全披露:这是一项任务。 我试图在用户被授予 DBA 角色时进行审计,并在事件发生时发送电子邮件。 我相信命令 AUDIT DBA;将审核对
我是一名优秀的程序员,十分优秀!