Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为什么将类注释为@Service不创建bean?_Java_Spring_Jakarta Ee_Ejb - Fatal编程技术网

Java 为什么将类注释为@Service不创建bean?

Java 为什么将类注释为@Service不创建bean?,java,spring,jakarta-ee,ejb,Java,Spring,Jakarta Ee,Ejb,我有这样的课: @Service("userDetailsService") public class MyUserDetailsService implements UserDetailsService { ... <beans:bean id="myUserDetailsService" class="my.package.services.MyUserDetailsService" /> 并努力做到: <authentication-manager>

我有这样的课:

@Service("userDetailsService") 
public class MyUserDetailsService implements UserDetailsService {
    ...
<beans:bean id="myUserDetailsService" class="my.package.services.MyUserDetailsService" />
并努力做到:

<authentication-manager>
    <authentication-provider user-service-ref="userDetailsService">
    </authentication-provider>
</authentication-manager>
其原因:

匹配的通配符是严格的,但找不到的声明 元素“上下文:注释配置”


@服务
扩展了允许类路径扫描的
@组件

您可以同时启用
类路径扫描
注释

<context:annotation-config />
<context:component-scan base-package="com.package.a,com.b" />

我不知道你用的是什么版本。试试这个

<authentication-manager>
    <authentication-provider user-service-ref="userDetailsService">
        <!-- <password-encoder hash="md5" /> -->
    </authentication-provider>
</authentication-manager>

除非您像提供名称一样提供名称,否则它将是类名。但您提供的名称与配置文件中的名称相同,但说明了另一个名称


如果你
@Service
没有名字,那就好了。

@Service
扩展了
@Component
,允许
类路径扫描

您可以同时启用
类路径扫描
注释

<context:annotation-config />
<context:component-scan base-package="com.package.a,com.b" />

我不知道你用的是什么版本。试试这个

<authentication-manager>
    <authentication-provider user-service-ref="userDetailsService">
        <!-- <password-encoder hash="md5" /> -->
    </authentication-provider>
</authentication-manager>

除非您像提供名称一样提供名称,否则它将是类名。但您提供的名称与配置文件中的名称相同,但说明了另一个名称


如果您
@Service
没有名字,那么就可以了。

如果您使用注释来指定bean,您需要在配置中添加一个条目,以便为它们添加注释

<context:component-scan base-package="org.example"/>

如果您使用注释来指定bean,您需要在配置中添加一个条目,以便为它们添加注释

<context:component-scan base-package="org.example"/>

您缺少上下文的架构位置

因此,您的xml应该从以下内容开始:

<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:jdbc="http://www.springframework.org/schema/jdbc" 
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           http://www.springframework.org/schema/jdbc
           http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
           http://www.springframework.org/schema/security
           http://www.springframework.org/schema/security/spring-security-3.0.xsd
           http://www.springframework.org/schema/context 
           http://www.springframework.org/schema/context/spring-context-3.0.xsd">

您缺少上下文的架构位置

因此,您的xml应该从以下内容开始:

<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:jdbc="http://www.springframework.org/schema/jdbc" 
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           http://www.springframework.org/schema/jdbc
           http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
           http://www.springframework.org/schema/security
           http://www.springframework.org/schema/security/spring-security-3.0.xsd
           http://www.springframework.org/schema/context 
           http://www.springframework.org/schema/context/spring-context-3.0.xsd">

只需使用

您可以做的另一件事是使用

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
path to the xml files separated by commas
</param-value>
</context-param>

上下文配置位置
用逗号分隔的xml文件的路径

只需使用

您可以做的另一件事是使用

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
path to the xml files separated by commas
</param-value>
</context-param>

上下文配置位置
用逗号分隔的xml文件的路径

Thx,我有那一行,但不在我的
security.xml
文件中。。。但即使添加了它,仍然存在一些问题,请检查editThx,我有一行,但不在我的
security.xml
文件中。。。但即使添加了它,仍然存在一些问题,请检查editThx,我有一行,但不在我的
security.xml
文件中。。。但即使添加了它,仍然存在一些问题,请检查editThx,我有一行,但不在我的
security.xml
文件中。。。但即使添加后,仍然存在一些问题,请检查编辑