如果没有任何初始化

发布于 2025-02-11 18:20:23 字数 1009 浏览 1 评论 0原文

我是Java的新手。我的Java类下方: -


@WebService
@SOAPBinding(style = SOAPBinding.Style.RPC, use = SOAPBinding.Use.LITERAL)
public class ABC extends AbstractWebService {

    protected ClassNameForService classNameForService;

    public void init() {
    }

    @WebMethod
    @Path("/test")
    @Produces("text/plain")
    @GET
    /**
     *
     * @return String
     */
    public String test(
        @WebParam(partName = "sessionID")
        @QueryParam("sessionID") String sessionID
    ) throws UserNotDefinedException
    {
    // does something here
    }
    
}

和下面是我的春季配置文件

 <bean id=”org.testproject.webservices.ABC class=”org.testproject.webservices.ABC init-method=”init” parent=”org.testproject.webservices.AbstractWebService”>
        <property name=classNameForService ref=”org.testproject.service.gb.ClassNameForService/>
    </bean>

,所以我们需要init-method =“ init”在这里?我可以从配置以及从类中删除“ init” 从类中删除是标准练习吗?

I am new to Java. I have below java class:-


@WebService
@SOAPBinding(style = SOAPBinding.Style.RPC, use = SOAPBinding.Use.LITERAL)
public class ABC extends AbstractWebService {

    protected ClassNameForService classNameForService;

    public void init() {
    }

    @WebMethod
    @Path("/test")
    @Produces("text/plain")
    @GET
    /**
     *
     * @return String
     */
    public String test(
        @WebParam(partName = "sessionID")
        @QueryParam("sessionID") String sessionID
    ) throws UserNotDefinedException
    {
    // does something here
    }
    
}

and below is my spring configuration file

 <bean id=”org.testproject.webservices.ABC class=”org.testproject.webservices.ABC init-method=”init” parent=”org.testproject.webservices.AbstractWebService”>
        <property name=classNameForService ref=”org.testproject.service.gb.ClassNameForService/>
    </bean>

So do we need init-method=”init” here? Can I remove init-method=”init” from configuration as well as init method from class, Is it a standard practice?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最佳男配角 2025-02-18 18:20:23

您不必指定初始方法(或为此销毁方法)。我认为值得注意的是,您问您是否是标准练习,我相信标准实践已从XML配置转变为注释驱动的方法,但出于您的问题的目的,在您的问题中,不包括初始方法时不包括初始方法不需要。

init-method类似于添加@PostContStruct在注释为bean上注释的方法。

You do NOT have to specify an init method (or destroy method for that matter). I think it's worth noting that you ask if it's standard practice, I believe the standard practice has moved away from the XML configuration to an annotation-driven approach but for the purpose of your question, it is standard practice to not include an init method when it is not needed.

The init-method is akin to adding a @PostContstruct annotated method on annotation declared beans.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文