问题标签 [spring-bean]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
3253 浏览

xml - Changing the value of an attribute with xslt

There are a number of other questions that deal with this area, but I can't make the solutions there work

I have a transform that splits up a Spring bean file containing multiple beans into a set of files, each with one bean

This works fine, producing files that start like this:

In order that the file looks identical to one originally created with just one bean in it (since the file will be checked into source code management, I want only real differences), I want to change the name="beanN" attribute to name="bean0" in each file. Note that generally the bean tag can contain additional attributes as well as the class and name ones.

Nothing I've tried based on other answers here works. Mostly, I get errors about "Cannot create an attribute node whose parent is a document node" and "Cannot create an attribute node after creating a child of the containing element".

So I'm missing something obvious. What do I need to add to make this extra change?

Update: the problem seems partly to do with the xml:space="preserve". This is presumably causing text nodes to be created. With that removed, I don't get the errors so often but I still can't get the transform right

(and the output has

How do I get a linefeed between these tags? I can use indent="yes" to get the output formatted, but I really want to preserve the input format as it was originally, making changes only where I have to)

Update: One of my many attempts. This one runs, but is basically an identity transform. result-doc is commented out to make debugging easier for now. I really don't understand properly how xsl:attribute works so a decent explanation of that might help.

0 投票
1 回答
390 浏览

grails - Grails Spring Security 自定义用户详细信息 Beans 被覆盖

我的应用架构是这样的:

所以我有一个插件,我围绕 spring-security 插件提供额外的实现,这在许多 Web 应用程序中都很常见。我做的一件事是使用自定义UserDetailsService.

我已经遵循了这方面的指南,并且当自定义用户详细信息的 bean 在中定义时,我可以让我的自定义安全插件独立运行grails-app/conf/spring/resources.groovy

由于它是一个插件,因此无法读取此文件,因此我将 bean 移到了doWithSpring {}闭包中。这在独立运行时仍然有效。

但是我现在发现的是,当使用 webapp 运行时,我的自定义详细信息服务被忽略,并且 Principal 现在是标准 GrailsUser

如果我将我的 bean 定义移动到网络应用程序中,grails-app/conf/spring/resources.groovy那么它就可以工作。但是我不想在每个使用这个插件的应用程序中定义这些 bean

我不确定发生了什么。userDetailsService()当 bean 作为 Web 应用程序中的插件运行时,为什么会忽略 bean?我可以看到其他 bean 正在正确设置(打印出所有 bean 名称并让自己成为一个 dummy bean)。它几乎就像它再次被挫败一样。

有什么地方可以定义这个 bean 以使其绝对有效吗?

解决这个问题的最佳方法是什么?

0 投票
1 回答
1210 浏览

java - 在spring配置中创建具有不同属性值的类的多个bean实例

我在 spring 配置中创建具有不同属性值的类的多个 bean 实例。例如:

我是 Spring 框架的新手,我只是想知道这样做的利弊。

0 投票
0 回答
1350 浏览

spring-bean - 我们可以在春天的 bean 的 id 值中有空间吗

我收到此错误:

我正在使用这个 spring-config.xml:

我的 bean id 值之间有空格。

这是我的主要课程:

但是,如果我将 spring-config 中的 xsd 更改为 spring-beans-3.1.xsd。我没有收到此错误。为什么会这样??

0 投票
2 回答
2216 浏览

spring-mvc - Spring:WebMvcConfigurerAdapter bean 注册了两次

这是Spring + Jackson + joda time的后续问题:如何指定序列化/反序列化格式?.

在写最终版代码的时候,第一次写成这样:(只显示相关部分)

没有 @EnableWebMvc,因为使用了 Spring Boot 的默认 @EnableWebMvc 类。
请注意,userInterceptor bean 在 WebMvcConfigurerAdapter 类中,它也是一个 bean。

当我运行应用程序时,出现以下错误:(
我的类的类路径名被我自己替换为'...')

然后我将 ApiWebMvcConfiguration 类更改为静态内部类。

应用程序“正常”启动,但 ApiWebMvcConfiguration 类被实例化了两次。也就是说,“### ApiWebMvcConfiguration”被打印了两次。因此,“### addInterceptors”被打印了两次。

然后,当 UserIntercepter 的代码运行时,它因为 null @Autowired JdbcTemplate 而失败。也就是说,@Autowired 不适用于该对象。(JdbcTemplate 在其他对象中成功@Autowired)

于是,我把代码改成了最终版本,如Spring + Jackson + joda time:如何指定序列化/反序列化格式?,即UserIntercepter bean被拉出ApiWebMvcConfiguration,问题就没有了。

这是正确的行为吗?
@Bean 不应该嵌套吗?

0 投票
1 回答
671 浏览

spring-mvc - Spring bean在启动时成功注入,但是在使用时给出空指针异常

我正在使用 Spring 3.0.6 Release 创建一个网络应用程序

我的问题是在启动服务器时,bean 注入成功.....但是当使用给出空指针异常时。

下面是我的 applicationContext.xml

控制器 GetAllDataController.java

请帮助我,为什么在调用 getPort() 方法时注入的 bean 对象为空?

0 投票
1 回答
2820 浏览

hybris - 我如何在运行时知道为我的 Spring bean 设置了哪些实现类?

在 hybris 中,是否有一种简单的方法可以知道某个 Spring bean 正在使用哪个实现类?

我的意思是,我可以通过执行以下操作来覆盖 Bean:

...所以现在当 Spring 需要使用别名创建一个 bean 时,checkoutFacade实现类将与在其他一些 xml 配置文件中定义MyCheckoutFacadeImpl的覆盖相反。defaultCheckoutFacade

那么有没有办法在运行时知道哪个实现类正在用于某个 Spring bean 定义?我的意思是,无需调试代码。

0 投票
4 回答
2124 浏览

java - @PostInitialize 哪个包的一部分

我希望在我的一个 bean 中使用 @PostInitialize 注释在初始化完成后加载一些属性。有人可以告诉我在哪里可以找到此注释吗?我需要添加什么 Maven 依赖项才能获得此注释?为什么这不是 Spring 3.2.4 的一部分,或者我错过了一些我应该添加的 spring 包?

请指教

更新

我尝试使用 resthubs @PostInitialize 但它不起作用。我是否必须进行任何其他配置才能使此注释起作用。

0 投票
1 回答
1189 浏览

spring - 什么是Spring bean bean的用途是什么

我是 Spring MVC 的初学者,我有一个问题是为什么要使用 bean。

据我所知,bean 只有带有 getter 和 setter 的私有变量。

我有几个问题,

是相同的bean出现在Spring MVC中,

为什么在 Spring 中使用 bean 定义 bean 的语法是什么

(我的项目是sampleSpr)sampleSpr-servlet.xml(在WEB-INF中)

有人可以帮我解决这些问题吗?

0 投票
2 回答
8641 浏览

spring - Spring bean定义——获取bean类

我正在尝试获取 Bean 类名而不初始化 bean。我需要知道类,我可以从 applicationContext 获取 bean 并从 bean 实例检查类名,但我想知道类而不实际创建/初始化 bean.. 可能吗?