例外:必须从Java代理开始才能使用InstrumentationLoadTimeWeaver。请参阅Spring文档

时间:2014-06-29 16:14:39

标签: java spring eclipselink jta

我在尝试执行测试时遇到异常 请帮忙 。 提前谢谢

我正在使用

Java 7,EclipseLink 2.5.0-SNAPSHOT,Spring 3.2.4

测试配置文件

<bean id="propertyConfigurer"
      class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
      p:location="classpath:jdbc.properties" />

<bean id="tttDataSource"
      class="org.springframework.jdbc.datasource.DriverManagerDataSource"
      p:driverClassName="${jdbc.driverClassName}"
      p:url="${jdbc.url}"
      p:username="${jdbc.username}"
      p:password="${jdbc.password}"
      />

<bean id="loadTimeWeaver" class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />

<bean id="jpaVendorAdapter" 
    class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter"
    p:showSql="true"
    p:databasePlatform="org.eclipse.persistence.platform.database.MySQLPlatform" />

<bean id="entityManagerFactory" 
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
    p:dataSource-ref="tttDataSource"
    p:jpaVendorAdapter-ref="jpaVendorAdapter"
    p:persistenceXmlLocation="test-persistence.xml"
/>

<!-- Transaction manager for a single JPA EntityManagerFactory (alternative to JTA) -->
<bean id="transactionManager" 
    class="org.springframework.orm.jpa.JpaTransactionManager"
    p:dataSource-ref="tttDataSource" 
    p:entityManagerFactory-ref="entityManagerFactory"/>

<!-- checks for annotated configured beans -->
<context:annotation-config/>  

<!-- Scan for Repository/Service annotations -->
<context:component-scan base-package="com.task.time.dao" />
<context:component-scan base-package="com.task.time.service" />
<context:component-scan base-package="com.task.time.web" />
<!-- enable the configuration of transactional behavior based on annotations -->
<tx:annotation-driven />

异常跟踪

java.lang.IllegalStateException: Failed to load ApplicationContext
    at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:99)
    at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:122)
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
    at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:312)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:288)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:284)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [testingContext.xml]: Invocation of init method failed; nested exception is java.lang.reflect.UndeclaredThrowableException
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1482)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1117)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:922)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
    at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:120)
    at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
    at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:100)
    at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:248)
    at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContextInternal(CacheAwareContextLoaderDelegate.java:64)
    at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:91)
    ... 25 more
Caused by: java.lang.reflect.UndeclaredThrowableException
    at com.sun.proxy.$Proxy13.addTransformer(Unknown Source)
    at org.eclipse.persistence.jpa.PersistenceProvider.createContainerEntityManagerFactory(PersistenceProvider.java:348)
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:288)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1541)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1479)
    ... 40 more
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager$Jpa2PersistenceUnitInfoDecorator.invoke(DefaultPersistenceUnitManager.java:617)
    ... 46 more
Caused by: java.lang.IllegalStateException: Must start with Java agent to use InstrumentationLoadTimeWeaver. See Spring documentation.
    at org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver.addTransformer(InstrumentationLoadTimeWeaver.java:87)
    at org.springframework.orm.jpa.persistenceunit.SpringPersistenceUnitInfo.addTransformer(SpringPersistenceUnitInfo.java:111)
    ... 51 more

4 个答案:

答案 0 :(得分:6)

如异常所示,请检查the documentation并尝试使用&#34; -javaagent&#34;运行测试,例如:

-javaagent:C:\Users\whatever\.m2\repository\org\springframework\spring-instrument\3.2.5.RELEASE\spring-instrument-3.2.5.RELEASE.jar

答案 1 :(得分:0)

这对我有用:

    string constr = ConfigurationManager.ConnectionStrings["restau"].ConnectionString;

            protected void Page_Load(object sender, EventArgs e)
            {
                //if (!IsPostBack)
                //{
                    BindEntree();
                //}
            }

            protected void BindEntree()
            {
                SqlConnection con = null;
                SqlCommand cmd = null;
                SqlDataAdapter sda = new SqlDataAdapter();
                DataSet ds = new DataSet();
                string strQuery = "select * from recette_restau2 where type_plat='entree' and prix_vente is not null and nbre_pers is not null and picture is not null";

                con = new SqlConnection(constr);

                try
                {
                    con.Open();

                    cmd = new SqlCommand(strQuery, con);

                    sda.SelectCommand = cmd;
                    sda.Fill(ds, "TableEntree");
                   
                    for (int i = 0; i < ds.Tables["TableEntree"].Rows.Count; i++)
                    { 
                        byte[] barrImg = (byte[])ds.Tables["TableEntree"].Rows[i][15];

                        if (barrImg != null && barrImg.Length > 0)
                        {
                            int identree = Convert.ToInt16(ds.Tables["TableEntree"].Rows[i][0]);

                            string base64String = Convert.ToBase64String(barrImg, 0, barrImg.Length);

                            System.Web.UI.HtmlControls.HtmlGenericControl divEntree = new System.Web.UI.HtmlControls.HtmlGenericControl("div");
                            divEntree.Attributes.Add("class", "panel panel-body");
                            divEntree.Style.Add("Border", "1px solid  #C7CAC9");
                            divEntree.Style.Add("BorderColor", "red");
                            divEntree.Style.Add("width", "350px");
                            divEntree.Style.Add("height", "350px");
                            divEntree.Style.Add("margin-right", "20px");
                            divEntree.Style.Add("margin-bottom", "20px");
                            divEntree.Style.Add("display", "flex");
                            divEntree.Style.Add("flex-direction", "column");
                            divEntree.Style.Add("justify-content", "space-between");

                            System.Web.UI.HtmlControls.HtmlGenericControl divInfo = new System.Web.UI.HtmlControls.HtmlGenericControl("div");

                            System.Web.UI.HtmlControls.HtmlGenericControl divTitrePrix = new System.Web.UI.HtmlControls.HtmlGenericControl("div");
                            divTitrePrix.Style.Add("display", "flex");
                            divTitrePrix.Style.Add("justify-content", "space-between");




                            Label lblTitre = new Label();
                            lblTitre.ID = "lblTitre" + i.ToString();
                            lblTitre.Style.Add("font-size", "1.5em");
                            lblTitre.Style.Add("margin-bottom", "10px");
                            lblTitre.Text = Convert.ToString(ds.Tables["TableEntree"].Rows[i][2]);

                            //Label lblObserv = new Label();
                            //lblObserv.ID = "lblObserv" + i.ToString();
                            //lblObserv.Text = Convert.ToString(ds.Tables["TableEntree"].Rows[i][16]);

                            TextBox lblPrix = new TextBox();
                            lblPrix.ID = "lblPrix" + i.ToString();
                            lblPrix.Style.Add("font-size", "1.1em");
                            lblPrix.Style.Add("margin-bottom", "10px");
                            lblPrix.Style.Add("height", "30px");
                            lblPrix.Style.Add("width", "70px");
                            lblPrix.Style.Add("color", "white");
                            lblPrix.Style.Add("background-color", "red");
                            lblPrix.Style.Add("justify-content", "center");
                            lblPrix.Style.Add("align-items", "center");
                            lblPrix.Style.Add("text-align", "center");
                            lblPrix.Attributes.Add("ReadOnly", "true");
                            lblPrix.Attributes.Add("enabled", "false");



                            lblPrix.Text = Convert.ToString(ds.Tables["TableEntree"].Rows[i][4] + " €");

                            Image ImageEntree = new Image();
                            ImageEntree.ImageUrl = "data:image/jpg;base64," + base64String;
                            ImageEntree.Style.Add("width", "50%");
                            ImageEntree.Style.Add("height", "50%");
                            ImageEntree.Style.Add("margin-right", "10px");



                            System.Web.UI.HtmlControls.HtmlGenericControl divChoix = new System.Web.UI.HtmlControls.HtmlGenericControl("div");
                            divChoix.Style.Add("display", "flex");
                            divChoix.Style.Add("justify-content", "center");
                            divChoix.Style.Add("align-items", "center");



                            System.Web.UI.HtmlControls.HtmlGenericControl divBtnMinusPlus = new System.Web.UI.HtmlControls.HtmlGenericControl("div");
                            divBtnMinusPlus.Attributes.Add("class", "input-group");
                            divBtnMinusPlus.Style.Add("margin-right", "10px");

                            System.Web.UI.WebControls.Image img1 = new System.Web.UI.WebControls.Image();
                            img1.ID = "img1" + i.ToString();
                            img1.Attributes.Add("width", "15px");
                            img1.Attributes.Add("height", "15px");
                            img1.Attributes.Add("OnClick", "img1_Click");
                            img1.ImageUrl = "Content/images/moins_rond.png";

                            System.Web.UI.WebControls.Image img2 = new System.Web.UI.WebControls.Image();
                            img2.ID = "img2" + i.ToString();
                            img2.Attributes.Add("OnClick", "img2_Click");
                            img2.ImageUrl = "Content/images/plus_rond.png";
                            img2.Attributes.Add("width", "15px");
                            img2.Attributes.Add("height", "15px");
                            
                            TextBox txtBoxNbre = new TextBox();
                            txtBoxNbre.ID = "txtBoxNbre" + i.ToString();
                            txtBoxNbre.Style.Add("width", "50px");
                            txtBoxNbre.Style.Add("text-align", "center");

                            AjaxControlToolkit.NumericUpDownExtender numericExtender = new AjaxControlToolkit.NumericUpDownExtender();
                            numericExtender.ID = "numericExtender" + i.ToString();
                            numericExtender.Width = 80;
                            numericExtender.Minimum = 1;
                            numericExtender.Maximum = 20;
                            numericExtender.TargetButtonUpID = "img2" + i.ToString();
                            numericExtender.TargetButtonDownID = "img1" + i.ToString();
                            numericExtender.TargetControlID = "txtBoxNbre" + i.ToString();




                            divBtnMinusPlus.Controls.Add(img1);
                            divBtnMinusPlus.Controls.Add(txtBoxNbre);
                            divBtnMinusPlus.Controls.Add(img2);
                            divBtnMinusPlus.Controls.Add(numericExtender);
                            
                            Button btnPrix = new Button();
                            btnPrix.ID = "btnPrix" + i.ToString();
                            //btnPrix.Attributes.Add("Class", "btn btn-danger hvr-icon-forward");
                            btnPrix.CssClass = "btn btn-danger hvr-icon-forward";
                            btnPrix.Attributes.Add("runat", "server");
                            btnPrix.Text = "Choisir";
                            btnPrix.Click += new System.EventHandler(btnPrix_Click);
                            //btnPrix.CommandArgument = "<%# Eval('id_recette') %>";

                            HiddenField hf = new HiddenField();
                            hf.ID = "hf" +i.ToString();
                            hf.Value = Convert.ToString(ds.Tables["TableEntree"].Rows[i][0]);



                            divTitrePrix.Controls.Add(lblTitre);
                            divTitrePrix.Controls.Add(lblPrix);




                            divInfo.Controls.Add(divTitrePrix);
                            //divInfo.Controls.Add(lblObserv);

                            divEntree.Controls.Add(divInfo);
                            divEntree.Controls.Add(new LiteralControl("<br />"));

                            divChoix.Controls.Add(ImageEntree);

                            divChoix.Controls.Add(divBtnMinusPlus);

                            divEntree.Controls.Add(divChoix);

                            divEntree.Controls.Add(new LiteralControl("<br />"));

                            divEntree.Controls.Add(btnPrix);

                            divEntree.Controls.Add(hf);




                            Panel_Entree.Controls.Add(divEntree);
                protected void btnPrix_Click(object sender, EventArgs e)
            {            
                                        try
                {//string s = (sender as Button).Text;
                    Button btn = (Button)sender;

                    string id = btn.CommandArgument;

                    Label1.Text = id;
                }
                catch (Exception ex)
                {
                    Label2.Text = ex.Message.ToString();

                }
                }

在配置类中添加:

    string constr = ConfigurationManager.ConnectionStrings["restau"].ConnectionString;

            protected void Page_Load(object sender, EventArgs e)
            {
                //if (!IsPostBack)
                //{
                    BindEntree();
                //}
            }

            protected void BindEntree()
            {
                SqlConnection con = null;
                SqlCommand cmd = null;
                SqlDataAdapter sda = new SqlDataAdapter();
                DataSet ds = new DataSet();
                string strQuery = "select * from recette_restau2 where type_plat='entree' and prix_vente is not null and nbre_pers is not null and picture is not null";

                con = new SqlConnection(constr);

                try
                {
                    con.Open();

                    cmd = new SqlCommand(strQuery, con);

                    sda.SelectCommand = cmd;
                    sda.Fill(ds, "TableEntree");
                   
                    for (int i = 0; i < ds.Tables["TableEntree"].Rows.Count; i++)
                    { 
                        byte[] barrImg = (byte[])ds.Tables["TableEntree"].Rows[i][15];

                        if (barrImg != null && barrImg.Length > 0)
                        {
                            int identree = Convert.ToInt16(ds.Tables["TableEntree"].Rows[i][0]);

                            string base64String = Convert.ToBase64String(barrImg, 0, barrImg.Length);

                            System.Web.UI.HtmlControls.HtmlGenericControl divEntree = new System.Web.UI.HtmlControls.HtmlGenericControl("div");
                            divEntree.Attributes.Add("class", "panel panel-body");
                            divEntree.Style.Add("Border", "1px solid  #C7CAC9");
                            divEntree.Style.Add("BorderColor", "red");
                            divEntree.Style.Add("width", "350px");
                            divEntree.Style.Add("height", "350px");
                            divEntree.Style.Add("margin-right", "20px");
                            divEntree.Style.Add("margin-bottom", "20px");
                            divEntree.Style.Add("display", "flex");
                            divEntree.Style.Add("flex-direction", "column");
                            divEntree.Style.Add("justify-content", "space-between");

                            System.Web.UI.HtmlControls.HtmlGenericControl divInfo = new System.Web.UI.HtmlControls.HtmlGenericControl("div");

                            System.Web.UI.HtmlControls.HtmlGenericControl divTitrePrix = new System.Web.UI.HtmlControls.HtmlGenericControl("div");
                            divTitrePrix.Style.Add("display", "flex");
                            divTitrePrix.Style.Add("justify-content", "space-between");




                            Label lblTitre = new Label();
                            lblTitre.ID = "lblTitre" + i.ToString();
                            lblTitre.Style.Add("font-size", "1.5em");
                            lblTitre.Style.Add("margin-bottom", "10px");
                            lblTitre.Text = Convert.ToString(ds.Tables["TableEntree"].Rows[i][2]);

                            //Label lblObserv = new Label();
                            //lblObserv.ID = "lblObserv" + i.ToString();
                            //lblObserv.Text = Convert.ToString(ds.Tables["TableEntree"].Rows[i][16]);

                            TextBox lblPrix = new TextBox();
                            lblPrix.ID = "lblPrix" + i.ToString();
                            lblPrix.Style.Add("font-size", "1.1em");
                            lblPrix.Style.Add("margin-bottom", "10px");
                            lblPrix.Style.Add("height", "30px");
                            lblPrix.Style.Add("width", "70px");
                            lblPrix.Style.Add("color", "white");
                            lblPrix.Style.Add("background-color", "red");
                            lblPrix.Style.Add("justify-content", "center");
                            lblPrix.Style.Add("align-items", "center");
                            lblPrix.Style.Add("text-align", "center");
                            lblPrix.Attributes.Add("ReadOnly", "true");
                            lblPrix.Attributes.Add("enabled", "false");



                            lblPrix.Text = Convert.ToString(ds.Tables["TableEntree"].Rows[i][4] + " €");

                            Image ImageEntree = new Image();
                            ImageEntree.ImageUrl = "data:image/jpg;base64," + base64String;
                            ImageEntree.Style.Add("width", "50%");
                            ImageEntree.Style.Add("height", "50%");
                            ImageEntree.Style.Add("margin-right", "10px");



                            System.Web.UI.HtmlControls.HtmlGenericControl divChoix = new System.Web.UI.HtmlControls.HtmlGenericControl("div");
                            divChoix.Style.Add("display", "flex");
                            divChoix.Style.Add("justify-content", "center");
                            divChoix.Style.Add("align-items", "center");



                            System.Web.UI.HtmlControls.HtmlGenericControl divBtnMinusPlus = new System.Web.UI.HtmlControls.HtmlGenericControl("div");
                            divBtnMinusPlus.Attributes.Add("class", "input-group");
                            divBtnMinusPlus.Style.Add("margin-right", "10px");

                            System.Web.UI.WebControls.Image img1 = new System.Web.UI.WebControls.Image();
                            img1.ID = "img1" + i.ToString();
                            img1.Attributes.Add("width", "15px");
                            img1.Attributes.Add("height", "15px");
                            img1.Attributes.Add("OnClick", "img1_Click");
                            img1.ImageUrl = "Content/images/moins_rond.png";

                            System.Web.UI.WebControls.Image img2 = new System.Web.UI.WebControls.Image();
                            img2.ID = "img2" + i.ToString();
                            img2.Attributes.Add("OnClick", "img2_Click");
                            img2.ImageUrl = "Content/images/plus_rond.png";
                            img2.Attributes.Add("width", "15px");
                            img2.Attributes.Add("height", "15px");
                            
                            TextBox txtBoxNbre = new TextBox();
                            txtBoxNbre.ID = "txtBoxNbre" + i.ToString();
                            txtBoxNbre.Style.Add("width", "50px");
                            txtBoxNbre.Style.Add("text-align", "center");

                            AjaxControlToolkit.NumericUpDownExtender numericExtender = new AjaxControlToolkit.NumericUpDownExtender();
                            numericExtender.ID = "numericExtender" + i.ToString();
                            numericExtender.Width = 80;
                            numericExtender.Minimum = 1;
                            numericExtender.Maximum = 20;
                            numericExtender.TargetButtonUpID = "img2" + i.ToString();
                            numericExtender.TargetButtonDownID = "img1" + i.ToString();
                            numericExtender.TargetControlID = "txtBoxNbre" + i.ToString();




                            divBtnMinusPlus.Controls.Add(img1);
                            divBtnMinusPlus.Controls.Add(txtBoxNbre);
                            divBtnMinusPlus.Controls.Add(img2);
                            divBtnMinusPlus.Controls.Add(numericExtender);
                            
                            Button btnPrix = new Button();
                            btnPrix.ID = "btnPrix" + i.ToString();
                            //btnPrix.Attributes.Add("Class", "btn btn-danger hvr-icon-forward");
                            btnPrix.CssClass = "btn btn-danger hvr-icon-forward";
                            btnPrix.Attributes.Add("runat", "server");
                            btnPrix.Text = "Choisir";
                            btnPrix.Click += new System.EventHandler(btnPrix_Click);
                            //btnPrix.CommandArgument = "<%# Eval('id_recette') %>";

                            HiddenField hf = new HiddenField();
                            hf.ID = "hf" +i.ToString();
                            hf.Value = Convert.ToString(ds.Tables["TableEntree"].Rows[i][0]);



                            divTitrePrix.Controls.Add(lblTitre);
                            divTitrePrix.Controls.Add(lblPrix);




                            divInfo.Controls.Add(divTitrePrix);
                            //divInfo.Controls.Add(lblObserv);

                            divEntree.Controls.Add(divInfo);
                            divEntree.Controls.Add(new LiteralControl("<br />"));

                            divChoix.Controls.Add(ImageEntree);

                            divChoix.Controls.Add(divBtnMinusPlus);

                            divEntree.Controls.Add(divChoix);

                            divEntree.Controls.Add(new LiteralControl("<br />"));

                            divEntree.Controls.Add(btnPrix);

                            divEntree.Controls.Add(hf);




                            Panel_Entree.Controls.Add(divEntree);
                protected void btnPrix_Click(object sender, EventArgs e)
            {            
                                        try
                {//string s = (sender as Button).Text;
                    Button btn = (Button)sender;

                    string id = btn.CommandArgument;

                    Label1.Text = id;
                }
                catch (Exception ex)
                {
                    Label2.Text = ex.Message.ToString();

                }
                }

将属性文件设置为:

spring-boot 1.5.3.RELEASE
spring-data 1.5.3.RELEASE

org.eclipse.persistence.jpa <version>2.6.4</version>
    </dependency>

并通过以下方式将Vm参数设置为本地服务器:

@Configuration
@EnableLoadTimeWeaving(aspectjWeaving = EnableLoadTimeWeaving.AspectJWeaving.ENABLED)

@Bean
public InstrumentationLoadTimeWeaver loadTimeWeaver()  throws Throwable {
    InstrumentationLoadTimeWeaver loadTimeWeaver = new InstrumentationLoadTimeWeaver();
    return loadTimeWeaver;
}

答案 2 :(得分:0)

我有类似的问题。我的解决方案是在tomcat conf目录的context.xml中添加一行。

<Context>
...
    <Loader delegate="true"/>
...
</Context>

答案 3 :(得分:0)

如果您正在运行类似构建的maven,请在您的surefire插件中添加一个额外的配置,如此代码段中所示(不要忘记在您的pom.xml中包含$ {spring-version}属性):

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.21.0</version>
    <configuration>
      <forkMode>once</forkMode>
      <argLine>
        -javaagent:"${settings.localRepository}/org/springframework/spring-instrument/${spring.version}/spring-instrument-${spring.version}.jar"
      </argLine>
    </configuration>
  </plugin>

this answer中的详细信息。